@@ -44,6 +44,52 @@ const char* ToCString(const String::Utf8Value& value) {
44
44
return *value ? *value : " <string conversion failed>" ;
45
45
}
46
46
47
+ /*
48
+ bool AbortOnUncaughtExceptionCallback(Isolate* isolate) {
49
+ return true;
50
+ }
51
+
52
+ void MessageCallback2(Local<Message> message, Local<Value> data) {
53
+ printf("MessageCallback2\n\n");
54
+ }
55
+
56
+ void FatalErrorCallback2(const char* location, const char* message) {
57
+ printf("FatalErrorCallback2\n");
58
+ }
59
+ */
60
+
61
+ void ExitOnPromiseRejectCallback (PromiseRejectMessage promise_reject_message) {
62
+ auto isolate = Isolate::GetCurrent ();
63
+ worker* w = (worker*)isolate->GetData (0 );
64
+ assert (w->isolate == isolate);
65
+ HandleScope handle_scope (w->isolate );
66
+ auto context = w->context .Get (w->isolate );
67
+
68
+ auto exception = promise_reject_message.GetValue ();
69
+
70
+ auto message = Exception::CreateMessage (isolate, exception );
71
+ auto onerrorStr = String::NewFromUtf8 (w->isolate , " onerror" );
72
+ auto onerror = context->Global ()->Get (onerrorStr);
73
+
74
+ if (onerror->IsFunction ()) {
75
+ Local<Function> func = Local<Function>::Cast (onerror);
76
+ Local<Value> args[5 ];
77
+ auto origin = message->GetScriptOrigin ();
78
+ args[0 ] = exception ->ToString ();
79
+ args[1 ] = message->GetScriptResourceName ();
80
+ args[2 ] = origin.ResourceLineOffset ();
81
+ args[3 ] = origin.ResourceColumnOffset ();
82
+ args[4 ] = exception ;
83
+ func->Call (context->Global (), 5 , args);
84
+ /* message, source, lineno, colno, error */
85
+ } else {
86
+ printf (" Unhandled Promise\n " );
87
+ message->PrintCurrentStackTrace (isolate, stdout);
88
+ }
89
+
90
+ exit (1 );
91
+ }
92
+
47
93
// Exception details will be appended to the first argument.
48
94
std::string ExceptionString (worker* w, TryCatch* try_catch) {
49
95
std::string out;
@@ -176,8 +222,7 @@ void Recv(const FunctionCallbackInfo<Value>& args) {
176
222
177
223
HandleScope handle_scope (isolate);
178
224
179
- Local<Context> context = Local<Context>::New (w->isolate , w->context );
180
- Context::Scope context_scope (context);
225
+ auto context = w->context .Get (w->isolate );
181
226
182
227
Local<Value> v = args[0 ];
183
228
assert (v->IsFunction ());
@@ -195,8 +240,7 @@ void Send(const FunctionCallbackInfo<Value>& args) {
195
240
Locker locker (w->isolate );
196
241
EscapableHandleScope handle_scope (isolate);
197
242
198
- Local<Context> context = Local<Context>::New (w->isolate , w->context );
199
- Context::Scope context_scope (context);
243
+ auto context = w->context .Get (w->isolate );
200
244
201
245
Local<Value> v = args[0 ];
202
246
assert (v->IsArrayBuffer ());
@@ -262,31 +306,6 @@ void v8_init() {
262
306
V8::Initialize ();
263
307
}
264
308
265
- /*
266
- bool AbortOnUncaughtExceptionCallback(Isolate* isolate) {
267
- return true;
268
- }
269
-
270
- void MessageCallback2(Local<Message> message, Local<Value> data) {
271
- printf("MessageCallback2\n\n");
272
- }
273
-
274
- void FatalErrorCallback2(const char* location, const char* message) {
275
- printf("FatalErrorCallback2\n");
276
- }
277
- */
278
-
279
- void ExitOnPromiseRejectCallback (PromiseRejectMessage message) {
280
- auto exception = message.GetValue ();
281
-
282
- auto isolate = Isolate::GetCurrent ();
283
- auto m = Exception::CreateMessage (isolate, exception );
284
-
285
- printf (" Unhandled Promise\n " );
286
- m->PrintCurrentStackTrace (isolate, stdout);
287
- exit (1 );
288
- }
289
-
290
309
worker* worker_new (int table_index) {
291
310
worker* w = new (worker);
292
311
0 commit comments