4
4
#include " node_buffer.h"
5
5
#include " node_platform.h"
6
6
#include " node_file.h"
7
+ #include " node_context_data.h"
7
8
#include " node_worker.h"
8
9
#include " tracing/agent.h"
9
10
@@ -28,6 +29,10 @@ using v8::Symbol;
28
29
using v8::Value;
29
30
using worker::Worker;
30
31
32
+ int const Environment::kNodeContextTag = 0x6e6f64 ;
33
+ void * Environment::kNodeContextTagPtr = const_cast <void *>(
34
+ static_cast <const void *>(&Environment::kNodeContextTag ));
35
+
31
36
IsolateData::IsolateData (Isolate* isolate,
32
37
uv_loop_t * event_loop,
33
38
MultiIsolatePlatform* platform,
@@ -430,7 +435,20 @@ bool Environment::RemovePromiseHook(promise_hook_func fn, void* arg) {
430
435
void Environment::EnvPromiseHook (v8::PromiseHookType type,
431
436
v8::Local<v8::Promise> promise,
432
437
v8::Local<v8::Value> parent) {
433
- Environment* env = Environment::GetCurrent (promise->CreationContext ());
438
+ Local<v8::Context> context = promise->CreationContext ();
439
+
440
+ // Grow the embedder data if necessary to make sure we are not out of bounds
441
+ // when reading the magic number.
442
+ context->SetAlignedPointerInEmbedderData (
443
+ ContextEmbedderIndex::kContextTagBoundary , nullptr );
444
+ int * magicNumberPtr = reinterpret_cast <int *>(
445
+ context->GetAlignedPointerFromEmbedderData (
446
+ ContextEmbedderIndex::kContextTag ));
447
+ if (magicNumberPtr != Environment::kNodeContextTagPtr ) {
448
+ return ;
449
+ }
450
+
451
+ Environment* env = Environment::GetCurrent (context);
434
452
for (const PromiseHookCallback& hook : env->promise_hooks_ ) {
435
453
hook.cb_ (type, promise, parent, hook.arg_ );
436
454
}
0 commit comments