-
-
Notifications
You must be signed in to change notification settings - Fork 39
Expand file tree
/
Copy pathV8PointerValue.cpp
More file actions
74 lines (64 loc) · 1.84 KB
/
Copy pathV8PointerValue.cpp
File metadata and controls
74 lines (64 loc) · 1.84 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/*
* Copyright (c) Kudo Chien.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#include "V8PointerValue.h"
namespace rnv8 {
V8PointerValue::V8PointerValue(
v8::Isolate *isolate,
const v8::Local<v8::Value> &value)
: isolate_(isolate), value_(isolate, value) {}
V8PointerValue::V8PointerValue(
v8::Isolate *isolate,
v8::Global<v8::Value> &&value)
: isolate_(isolate), value_(std::move(value)) {}
V8PointerValue::~V8PointerValue() {}
v8::Local<v8::Value> V8PointerValue::Get(v8::Isolate *isolate) const {
v8::EscapableHandleScope scopedHandle(isolate);
return scopedHandle.Escape(value_.Get(isolate));
}
// static
V8PointerValue *V8PointerValue::createFromOneByte(
v8::Isolate *isolate,
const char *str,
size_t length) {
v8::HandleScope scopedHandle(isolate);
v8::Local<v8::String> v8String;
if (!v8::String::NewFromOneByte(
isolate,
reinterpret_cast<const uint8_t *>(str),
v8::NewStringType::kNormal,
static_cast<int>(length))
.ToLocal(&v8String)) {
return nullptr;
}
return new V8PointerValue(isolate, v8String);
}
// static
V8PointerValue *V8PointerValue::createFromUtf8(
v8::Isolate *isolate,
const uint8_t *str,
size_t length) {
v8::HandleScope scopedHandle(isolate);
v8::Local<v8::String> v8String;
if (!v8::String::NewFromUtf8(
isolate,
reinterpret_cast<const char *>(str),
v8::NewStringType::kNormal,
static_cast<int>(length))
.ToLocal(&v8String)) {
return nullptr;
}
return new V8PointerValue(isolate, v8String);
}
void V8PointerValue::invalidate() {
{
v8::Locker locker(isolate_);
v8::Isolate::Scope scopedIsolate(isolate_);
value_.Reset();
}
delete this;
}
} // namespace rnv8