|
3 | 3 |
|
4 | 4 | namespace v8 { |
5 | 5 |
|
| 6 | +extern "C" { |
| 7 | + V8_EXTERN internal::Address _v8_globalize_reference( |
| 8 | + internal::Isolate* isolate, internal::Address value); |
| 9 | + V8_EXTERN void _v8_dispose_global(internal::Address global_handle); |
| 10 | + V8_EXTERN void _v8_make_weak(internal::Address location, |
| 11 | + void* data, |
| 12 | + void (*callback)( |
| 13 | + WeakCallbackInfo<void>::Callback weak_callback, |
| 14 | + void* data, WeakCallbackType type, |
| 15 | + void* internal_field1, void* internal_field2), |
| 16 | + WeakCallbackInfo<void>::Callback weak_callback, |
| 17 | + WeakCallbackType type); |
| 18 | + V8_EXTERN void* _v8_clear_weak(internal::Address location); |
| 19 | +} |
| 20 | + |
6 | 21 | namespace internal { |
7 | 22 |
|
8 | 23 | Isolate* IsolateFromNeverReadOnlySpaceObject(unsigned long obj) { |
@@ -38,6 +53,47 @@ void FromJustIsNothing() { |
38 | 53 | abort(); |
39 | 54 | } |
40 | 55 |
|
| 56 | +internal::Address* GlobalizeReference(internal::Isolate* isolate, |
| 57 | + internal::Address value) { |
| 58 | + internal::Address ref_id = _v8_globalize_reference(isolate, value); |
| 59 | + return new internal::Address(ref_id); |
| 60 | +} |
| 61 | + |
| 62 | +void DisposeGlobal(internal::Address* global_handle) { |
| 63 | + _v8_dispose_global(*global_handle); |
| 64 | + delete global_handle; |
| 65 | +} |
| 66 | + |
| 67 | +namespace { |
| 68 | +static void WeakCallback(WeakCallbackInfo<void>::Callback weak_callback, |
| 69 | + void* data, |
| 70 | + WeakCallbackType type, |
| 71 | + void* internal_field1, |
| 72 | + void* internal_field2) { |
| 73 | + void* embedder_fields[kEmbedderFieldsInWeakCallback] = { |
| 74 | + internal_field1, internal_field2 |
| 75 | + }; |
| 76 | + WeakCallbackInfo<void>::Callback second = nullptr; |
| 77 | + WeakCallbackInfo<void> info( |
| 78 | + Isolate::GetCurrent(), data, |
| 79 | + embedder_fields, &second); |
| 80 | + weak_callback(info); |
| 81 | + if (second != nullptr) { |
| 82 | + second(info); |
| 83 | + } |
| 84 | +} |
| 85 | +} |
| 86 | + |
| 87 | +void MakeWeak(internal::Address* location, void* data, |
| 88 | + WeakCallbackInfo<void>::Callback weak_callback, |
| 89 | + WeakCallbackType type) { |
| 90 | + _v8_make_weak(*location, data, WeakCallback, weak_callback, type); |
| 91 | +} |
| 92 | + |
| 93 | +void* ClearWeak(internal::Address* location) { |
| 94 | + return _v8_clear_weak(*location); |
| 95 | +}; |
| 96 | + |
41 | 97 | } // namespace api_internal |
42 | 98 |
|
43 | 99 | } // namespace v8 |
0 commit comments