summaryrefslogtreecommitdiff
path: root/chromium/third_party/blink/renderer/platform/bindings/trace_wrapper_v8_string.h
blob: 5af791f53328b24739c1529babd45f41a71bad77 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef THIRD_PARTY_BLINK_RENDERER_PLATFORM_BINDINGS_TRACE_WRAPPER_V8_STRING_H_
#define THIRD_PARTY_BLINK_RENDERER_PLATFORM_BINDINGS_TRACE_WRAPPER_V8_STRING_H_

#include "third_party/blink/renderer/platform/bindings/name_client.h"
#include "third_party/blink/renderer/platform/bindings/trace_wrapper_v8_reference.h"
#include "third_party/blink/renderer/platform/wtf/forward.h"
#include "v8/include/v8.h"

namespace blink {

// Small shim around TraceWrapperReference<v8::String> with a few
// utility methods. Internally, v8::String is represented as string
// rope.
class GC_PLUGIN_IGNORE("crbug.com/841830")
    PLATFORM_EXPORT TraceWrapperV8String final : public NameClient {
  DISALLOW_COPY_AND_ASSIGN(TraceWrapperV8String);
  DISALLOW_NEW();

 public:
  TraceWrapperV8String() = default;

  bool IsEmpty() const { return string_.IsEmpty(); }
  void Clear() { string_.Clear(); }

  v8::Local<v8::String> V8Value(v8::Isolate* isolate) {
    return string_.NewLocal(isolate);
  }

  void Concat(v8::Isolate*, const String&);
  String Flatten(v8::Isolate*) const;

  virtual void Trace(Visitor* visitor) { visitor->Trace(string_); }

  const char* NameInHeapSnapshot() const override {
    return "TraceWrapperV8String";
  }

 private:
  TraceWrapperV8Reference<v8::String> string_;
};

}  // namespace blink

#endif  // THIRD_PARTY_BLINK_RENDERER_PLATFORM_BINDINGS_TRACE_WRAPPER_V8_STRING_H_