|
1 | 1 | #include "PromiseProxy.h" |
| 2 | + |
2 | 3 | #include "Helpers.h" |
3 | 4 |
|
4 | 5 | using namespace v8; |
5 | 6 |
|
6 | 7 | namespace tns { |
7 | 8 |
|
8 | 9 | void PromiseProxy::Init(v8::Local<v8::Context> context) { |
9 | | - std::string source = R"( |
| 10 | + std::string source = R"( |
10 | 11 | // Ensure that Promise callbacks are executed on the |
11 | 12 | // same thread on which they were created |
12 | 13 | (() => { |
@@ -72,18 +73,40 @@ void PromiseProxy::Init(v8::Local<v8::Context> context) { |
72 | 73 | }); |
73 | 74 | } |
74 | 75 | }); |
| 76 | + globalThis = new Proxy(globalThis, { |
| 77 | + defineProperty: (target, prop, descriptor) => { |
| 78 | + if (prop === 'Promise') { |
| 79 | + return true; |
| 80 | + } |
| 81 | + return Object.defineProperty(target, prop, descriptor); |
| 82 | + }, |
| 83 | + set: (target, prop, value, receiver) => { |
| 84 | + if (prop === 'Promise') { |
| 85 | + return true; |
| 86 | + } |
| 87 | + |
| 88 | + const descriptor = Object.getOwnPropertyDescriptor(target, prop); |
| 89 | + if (descriptor && !descriptor.writable) { |
| 90 | + return false; |
| 91 | + } |
| 92 | +
|
| 93 | + target[prop] = value; |
| 94 | + return true; |
| 95 | + } |
| 96 | + }); |
75 | 97 | })(); |
76 | 98 | )"; |
77 | 99 |
|
78 | | - Isolate* isolate = context->GetIsolate(); |
| 100 | + Isolate* isolate = context->GetIsolate(); |
79 | 101 |
|
80 | | - Local<Script> script; |
81 | | - bool success = Script::Compile(context, tns::ToV8String(isolate, source)).ToLocal(&script); |
82 | | - tns::Assert(success && !script.IsEmpty(), isolate); |
| 102 | + Local<Script> script; |
| 103 | + bool success = Script::Compile(context, tns::ToV8String(isolate, source)) |
| 104 | + .ToLocal(&script); |
| 105 | + tns::Assert(success && !script.IsEmpty(), isolate); |
83 | 106 |
|
84 | | - Local<Value> result; |
85 | | - success = script->Run(context).ToLocal(&result); |
86 | | - tns::Assert(success, isolate); |
| 107 | + Local<Value> result; |
| 108 | + success = script->Run(context).ToLocal(&result); |
| 109 | + tns::Assert(success, isolate); |
87 | 110 | } |
88 | 111 |
|
89 | | -} |
| 112 | +} // namespace tns |
0 commit comments