diff --git a/src/d8/d8.cc b/src/d8/d8.cc index 3a04345b0f..5af3e45e9a 100644 --- a/src/d8/d8.cc +++ b/src/d8/d8.cc @@ -644,9 +644,39 @@ MaybeLocal Shell::CompileString(Isolate* isolate, Local context, return result; } +namespace { +// For testing. +const int kHostDefinedOptionsLength = 2; +const uint32_t kHostDefinedOptionsMagicConstant = 0xF1F2F3F0; + +ScriptOrigin CreateScriptOrigin(Isolate* isolate, Local resource_name, + v8::ScriptType type) { + Local options = + PrimitiveArray::New(isolate, kHostDefinedOptionsLength); + options->Set(isolate, 0, + v8::Uint32::New(isolate, kHostDefinedOptionsMagicConstant)); + options->Set(isolate, 1, resource_name); + return ScriptOrigin(isolate, resource_name, 0, 0, false, -1, Local(), + false, false, type == v8::ScriptType::kModule, options); +} + +bool IsValidHostDefinedOptions(Local context, + Local options, + Local script_or_module) { + Isolate* isolate = context->GetIsolate(); + if (options->Length() != kHostDefinedOptionsLength) return false; + uint32_t magic = 0; + if (!options->Get(isolate, 0)->Uint32Value(context).To(&magic)) return false; + if (magic != kHostDefinedOptionsMagicConstant) return false; + return options->Get(isolate, 1) + .As() + ->StrictEquals(script_or_module->GetResourceName()); +} +} // namespace + // Executes a string within the current v8 context. bool Shell::ExecuteString(Isolate* isolate, Local source, - Local name, PrintResult print_result, + Local name, PrintResult print_result, ReportExceptions report_exceptions, ProcessMessageQueue process_message_queue) { i::Isolate* i_isolate = reinterpret_cast(isolate); @@ -702,9 +732,9 @@ bool Shell::ExecuteString(Isolate* isolate, Local source, Local realm = Local::New(isolate, data->realms_[data->realm_current_]); Context::Scope context_scope(realm); - MaybeLocal