@@ -27,75 +27,75 @@ using v8::MaybeLocal;
27
27
28
28
template <typename ResourceType, typename TypeName>
29
29
class ExternString : public ResourceType {
30
- public:
31
- ~ExternString () override {
32
- free (const_cast <TypeName*>(data_));
33
- isolate ()->AdjustAmountOfExternalAllocatedMemory (-byte_length ());
34
- }
35
-
36
- const TypeName* data () const override {
37
- return data_;
38
- }
30
+ public:
31
+ ~ExternString () override {
32
+ free (const_cast <TypeName*>(data_));
33
+ isolate ()->AdjustAmountOfExternalAllocatedMemory (-byte_length ());
34
+ }
39
35
40
- size_t length () const override {
41
- return length_ ;
42
- }
36
+ const TypeName* data () const override {
37
+ return data_ ;
38
+ }
43
39
44
- int64_t byte_length () const {
45
- return length () * sizeof (* data ()) ;
46
- }
40
+ size_t length () const override {
41
+ return length_ ;
42
+ }
47
43
48
- static Local<String> NewFromCopy (Isolate* isolate,
49
- const TypeName* data,
50
- size_t length) {
51
- EscapableHandleScope scope (isolate);
44
+ int64_t byte_length () const {
45
+ return length () * sizeof (*data ());
46
+ }
52
47
53
- if (length == 0 )
54
- return scope.Escape (String::Empty (isolate));
48
+ static Local<String> NewFromCopy (Isolate* isolate,
49
+ const TypeName* data,
50
+ size_t length) {
51
+ EscapableHandleScope scope (isolate);
55
52
56
- TypeName* new_data =
57
- static_cast <TypeName*>(malloc (length * sizeof (*new_data)));
58
- if (new_data == nullptr ) {
59
- return Local<String>();
60
- }
61
- memcpy (new_data, data, length * sizeof (*new_data));
53
+ if (length == 0 )
54
+ return scope.Escape (String::Empty (isolate));
62
55
63
- return scope.Escape (ExternString<ResourceType, TypeName>::New (isolate,
64
- new_data,
65
- length));
56
+ TypeName* new_data =
57
+ static_cast <TypeName*>(malloc (length * sizeof (*new_data)));
58
+ if (new_data == nullptr ) {
59
+ return Local<String>();
66
60
}
61
+ memcpy (new_data, data, length * sizeof (*new_data));
67
62
68
- // uses "data" for external resource, and will be free'd on gc
69
- static Local<String> New (Isolate* isolate,
70
- const TypeName* data,
71
- size_t length) {
72
- EscapableHandleScope scope (isolate);
63
+ return scope.Escape (ExternString<ResourceType, TypeName>::New (isolate,
64
+ new_data,
65
+ length));
66
+ }
73
67
74
- if (length == 0 )
75
- return scope.Escape (String::Empty (isolate));
68
+ // uses "data" for external resource, and will be free'd on gc
69
+ static Local<String> New (Isolate* isolate,
70
+ const TypeName* data,
71
+ size_t length) {
72
+ EscapableHandleScope scope (isolate);
73
+ if (length == 0 )
74
+ return scope.Escape (String::Empty (isolate));
76
75
77
- ExternString* h_str = new ExternString<ResourceType, TypeName>(isolate,
78
- data,
79
- length);
80
- MaybeLocal<String> str = String::NewExternal (isolate, h_str);
81
- isolate->AdjustAmountOfExternalAllocatedMemory (h_str->byte_length ());
76
+ ExternString* h_str = new ExternString<ResourceType, TypeName>(isolate,
77
+ data,
78
+ length);
79
+ MaybeLocal<String> str = String::NewExternal (isolate, h_str);
80
+ isolate->AdjustAmountOfExternalAllocatedMemory (h_str->byte_length ());
82
81
83
- if (str.IsEmpty ()) {
84
- delete h_str;
85
- return Local<String>();
86
- }
87
82
88
- return scope.Escape (str.ToLocalChecked ());
83
+ if (str.IsEmpty ()) {
84
+ delete h_str;
85
+ return Local<String>();
89
86
}
90
87
91
- inline Isolate* isolate () const { return isolate_; }
88
+ return scope.Escape (str.ToLocalChecked ());
89
+ }
90
+
91
+ inline Isolate* isolate () const { return isolate_; }
92
92
93
- private:
94
- ExternString (Isolate* isolate, const TypeName* data, size_t length)
95
- : isolate_(isolate), data_(data), length_(length) { }
96
- Isolate* isolate_;
97
- const TypeName* data_;
98
- size_t length_;
93
+ private:
94
+ ExternString (Isolate* isolate, const TypeName* data, size_t length)
95
+ : isolate_(isolate), data_(data), length_(length) { }
96
+ Isolate* isolate_;
97
+ const TypeName* data_;
98
+ size_t length_;
99
99
};
100
100
101
101
0 commit comments