Skip to content

Commit 11566fe

Browse files
Jan KremsMylesBorins
Jan Krems
authored andcommitted
deps: cherry-pick dbfe4a49d8 from upstream V8
Original commit message: Introduce ScriptOrModule and HostDefinedOptions This patch introduces a new container type ScriptOrModule which provides the name and the host defined options of the script/module. This patch also introduces a new PrimitivesArray that can hold Primitive values, which the embedder can use to store metadata. The HostDefinedOptions is passed to V8 through the ScriptOrigin, and passed back to the embedder through HostImportModuleDynamically for module loading. Bug: v8:5785, v8:6658, v8:6683 Cq-Include-Trybots: master.tryserver.chromium.linux:linux_chromium_rel_ng Change-Id: I56c26fc9a680b273ac0a6691e5ad75f15b8dc80a Reviewed-on: https://chromium-review.googlesource.com/622158 Reviewed-by: Adam Klein <[email protected]> Reviewed-by: Georg Neis <[email protected]> Commit-Queue: Sathya Gunasekaran <[email protected]> Cr-Commit-Position: refs/heads/master@{#47724} Backport-PR-URL: #17823 PR-URL: #16889 Refs: v8/v8@dbfe4a4 Refs: #15713 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Michaël Zasso <[email protected]>
1 parent 3725d4c commit 11566fe

20 files changed

+302
-47
lines changed

common.gypi

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
# Reset this number to 0 on major V8 upgrades.
2929
# Increment by one for each non-official patch applied to deps/v8.
30-
'v8_embedder_string': '-node.18',
30+
'v8_embedder_string': '-node.19',
3131

3232
# Enable disassembler for `--print-code` v8 options
3333
'v8_enable_disassembler': 1,

deps/v8/include/v8.h

+67-8
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ class String;
104104
class StringObject;
105105
class Symbol;
106106
class SymbolObject;
107+
class PrimitiveArray;
107108
class Private;
108109
class Uint32;
109110
class Utils;
@@ -978,6 +979,48 @@ class V8_EXPORT Data {
978979
Data();
979980
};
980981

982+
/**
983+
* This is an unfinished experimental feature, and is only exposed
984+
* here for internal testing purposes. DO NOT USE.
985+
*
986+
* A container type that holds relevant metadata for module loading.
987+
*
988+
* This is passed back to the embedder as part of
989+
* HostImportDynamicallyCallback for module loading.
990+
*/
991+
class V8_EXPORT ScriptOrModule {
992+
public:
993+
/**
994+
* The name that was passed by the embedder as ResourceName to the
995+
* ScriptOrigin. This can be either a v8::String or v8::Undefined.
996+
*/
997+
Local<Value> GetResourceName();
998+
999+
/**
1000+
* The options that were passed by the embedder as HostDefinedOptions to
1001+
* the ScriptOrigin.
1002+
*/
1003+
Local<PrimitiveArray> GetHostDefinedOptions();
1004+
};
1005+
1006+
/**
1007+
* This is an unfinished experimental feature, and is only exposed
1008+
* here for internal testing purposes. DO NOT USE.
1009+
*
1010+
* An array to hold Primitive values. This is used by the embedder to
1011+
* pass host defined options to the ScriptOptions during compilation.
1012+
*
1013+
* This is passed back to the embedder as part of
1014+
* HostImportDynamicallyCallback for module loading.
1015+
*
1016+
*/
1017+
class V8_EXPORT PrimitiveArray {
1018+
public:
1019+
static Local<PrimitiveArray> New(Isolate* isolate, int length);
1020+
int Length() const;
1021+
void Set(int index, Local<Primitive> item);
1022+
Local<Primitive> Get(int index);
1023+
};
9811024

9821025
/**
9831026
* The optional attributes of ScriptOrigin.
@@ -1027,13 +1070,17 @@ class ScriptOrigin {
10271070
Local<Value> source_map_url = Local<Value>(),
10281071
Local<Boolean> resource_is_opaque = Local<Boolean>(),
10291072
Local<Boolean> is_wasm = Local<Boolean>(),
1030-
Local<Boolean> is_module = Local<Boolean>());
1073+
Local<Boolean> is_module = Local<Boolean>() /*,
1074+
// Backed out for ABI compatibility with V8 6.2
1075+
Local<PrimitiveArray> host_defined_options = Local<PrimitiveArray>() */);
10311076

10321077
V8_INLINE Local<Value> ResourceName() const;
10331078
V8_INLINE Local<Integer> ResourceLineOffset() const;
10341079
V8_INLINE Local<Integer> ResourceColumnOffset() const;
10351080
V8_INLINE Local<Integer> ScriptID() const;
10361081
V8_INLINE Local<Value> SourceMapUrl() const;
1082+
// Backed out for ABI compatibility with V8 6.2
1083+
// V8_INLINE Local<PrimitiveArray> HostDefinedOptions() const;
10371084
V8_INLINE ScriptOriginOptions Options() const { return options_; }
10381085

10391086
private:
@@ -1043,6 +1090,8 @@ class ScriptOrigin {
10431090
ScriptOriginOptions options_;
10441091
Local<Integer> script_id_;
10451092
Local<Value> source_map_url_;
1093+
// Backed out for ABI compatibility with V8 6.2
1094+
// Local<PrimitiveArray> host_defined_options_;
10461095
};
10471096

10481097
/**
@@ -1289,6 +1338,7 @@ class V8_EXPORT ScriptCompiler {
12891338
Local<Integer> resource_column_offset;
12901339
ScriptOriginOptions resource_options;
12911340
Local<Value> source_map_url;
1341+
// Local<PrimitiveArray> host_defined_options;
12921342

12931343
// Cached data from previous compilation (if a kConsume*Cache flag is
12941344
// set), or hold newly generated cache data (kProduce*Cache flags) are
@@ -6209,8 +6259,8 @@ typedef void (*DeprecatedCallCompletedCallback)();
62096259
* embedder to load a module. This is used as part of the dynamic
62106260
* import syntax.
62116261
*
6212-
* The referrer is the name of the file which calls the dynamic
6213-
* import. The referrer can be used to resolve the module location.
6262+
* The referrer contains metadata about the script/module that calls
6263+
* import.
62146264
*
62156265
* The specifier is the name of the module that should be imported.
62166266
*
@@ -6225,7 +6275,8 @@ typedef void (*DeprecatedCallCompletedCallback)();
62256275
* that exception by returning an empty MaybeLocal.
62266276
*/
62276277
typedef MaybeLocal<Promise> (*HostImportModuleDynamicallyCallback)(
6228-
Local<Context> context, Local<String> referrer, Local<String> specifier);
6278+
Local<Context> context, Local<ScriptOrModule> referrer,
6279+
Local<String> specifier);
62296280

62306281
/**
62316282
* PromiseHook with type kInit is called when a new promise is
@@ -9545,7 +9596,9 @@ ScriptOrigin::ScriptOrigin(Local<Value> resource_name,
95459596
Local<Integer> script_id,
95469597
Local<Value> source_map_url,
95479598
Local<Boolean> resource_is_opaque,
9548-
Local<Boolean> is_wasm, Local<Boolean> is_module)
9599+
Local<Boolean> is_wasm, Local<Boolean> is_module /*,
9600+
// Backed out for ABI compatibility with V8 6.2
9601+
Local<PrimitiveArray> host_defined_options */)
95499602
: resource_name_(resource_name),
95509603
resource_line_offset_(resource_line_offset),
95519604
resource_column_offset_(resource_column_offset),
@@ -9555,10 +9608,16 @@ ScriptOrigin::ScriptOrigin(Local<Value> resource_name,
95559608
!is_wasm.IsEmpty() && is_wasm->IsTrue(),
95569609
!is_module.IsEmpty() && is_module->IsTrue()),
95579610
script_id_(script_id),
9558-
source_map_url_(source_map_url) {}
9611+
source_map_url_(source_map_url) /*,
9612+
// Backed out for ABI compatibility with V8 6.2
9613+
host_defined_options_(host_defined_options) */ {}
95599614

95609615
Local<Value> ScriptOrigin::ResourceName() const { return resource_name_; }
95619616

9617+
// Backed out for ABI compatibility with V8 6.2
9618+
// Local<PrimitiveArray> ScriptOrigin::HostDefinedOptions() const {
9619+
// return host_defined_options_;
9620+
// }
95629621

95639622
Local<Integer> ScriptOrigin::ResourceLineOffset() const {
95649623
return resource_line_offset_;
@@ -9575,7 +9634,6 @@ Local<Integer> ScriptOrigin::ScriptID() const { return script_id_; }
95759634

95769635
Local<Value> ScriptOrigin::SourceMapUrl() const { return source_map_url_; }
95779636

9578-
95799637
ScriptCompiler::Source::Source(Local<String> string, const ScriptOrigin& origin,
95809638
CachedData* data)
95819639
: source_string(string),
@@ -9584,9 +9642,10 @@ ScriptCompiler::Source::Source(Local<String> string, const ScriptOrigin& origin,
95849642
resource_column_offset(origin.ResourceColumnOffset()),
95859643
resource_options(origin.Options()),
95869644
source_map_url(origin.SourceMapUrl()),
9645+
// Backed out for ABI compatibility with V8 6.2
9646+
// host_defined_options(origin.HostDefinedOptions()),
95879647
cached_data(data) {}
95889648

9589-
95909649
ScriptCompiler::Source::Source(Local<String> string,
95919650
CachedData* data)
95929651
: source_string(string), cached_data(data) {}

deps/v8/src/api.cc

+78-3
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,9 @@ static ScriptOrigin GetScriptOriginForScript(i::Isolate* isolate,
278278
i::Handle<i::Script> script) {
279279
i::Handle<i::Object> scriptName(script->GetNameOrSourceURL(), isolate);
280280
i::Handle<i::Object> source_map_url(script->source_mapping_url(), isolate);
281+
// Backed out for ABI compatibility with V8 6.2
282+
// i::Handle<i::FixedArray> host_defined_options(script->host_defined_options(),
283+
// isolate);
281284
v8::Isolate* v8_isolate =
282285
reinterpret_cast<v8::Isolate*>(script->GetIsolate());
283286
ScriptOriginOptions options(script->origin_options());
@@ -290,7 +293,9 @@ static ScriptOrigin GetScriptOriginForScript(i::Isolate* isolate,
290293
Utils::ToLocal(source_map_url),
291294
v8::Boolean::New(v8_isolate, options.IsOpaque()),
292295
v8::Boolean::New(v8_isolate, script->type() == i::Script::TYPE_WASM),
293-
v8::Boolean::New(v8_isolate, options.IsModule()));
296+
v8::Boolean::New(v8_isolate, options.IsModule()) /*,
297+
// Backed out for ABI compatibility with V8 6.2
298+
Utils::ToLocal(host_defined_options) */);
294299
return origin;
295300
}
296301

@@ -2082,13 +2087,70 @@ Local<Value> Script::Run() {
20822087
RETURN_TO_LOCAL_UNCHECKED(Run(context), Value);
20832088
}
20842089

2090+
Local<Value> ScriptOrModule::GetResourceName() {
2091+
i::Handle<i::Script> obj = Utils::OpenHandle(this);
2092+
i::Isolate* isolate = obj->GetIsolate();
2093+
ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
2094+
i::Handle<i::Object> val(obj->name(), isolate);
2095+
return ToApiHandle<Value>(val);
2096+
}
2097+
2098+
Local<PrimitiveArray> ScriptOrModule::GetHostDefinedOptions() {
2099+
i::Handle<i::Script> obj = Utils::OpenHandle(this);
2100+
i::Isolate* isolate = obj->GetIsolate();
2101+
ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
2102+
// Backed out for ABI compatibility with V8 6.2
2103+
// i::Handle<i::FixedArray> val(obj->host_defined_options(), isolate);
2104+
// return ToApiHandle<PrimitiveArray>(val);
2105+
return Local<PrimitiveArray>();
2106+
}
20852107

20862108
Local<UnboundScript> Script::GetUnboundScript() {
20872109
i::Handle<i::Object> obj = Utils::OpenHandle(this);
20882110
return ToApiHandle<UnboundScript>(
20892111
i::Handle<i::SharedFunctionInfo>(i::JSFunction::cast(*obj)->shared()));
20902112
}
20912113

2114+
// static
2115+
Local<PrimitiveArray> PrimitiveArray::New(Isolate* v8_isolate, int length) {
2116+
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
2117+
ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
2118+
Utils::ApiCheck(length >= 0, "v8::PrimitiveArray::New",
2119+
"length must be equal or greater than zero");
2120+
i::Handle<i::FixedArray> array = isolate->factory()->NewFixedArray(length);
2121+
return ToApiHandle<PrimitiveArray>(array);
2122+
}
2123+
2124+
int PrimitiveArray::Length() const {
2125+
i::Handle<i::FixedArray> array = Utils::OpenHandle(this);
2126+
i::Isolate* isolate = array->GetIsolate();
2127+
ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
2128+
return array->length();
2129+
}
2130+
2131+
void PrimitiveArray::Set(int index, Local<Primitive> item) {
2132+
i::Handle<i::FixedArray> array = Utils::OpenHandle(this);
2133+
i::Isolate* isolate = array->GetIsolate();
2134+
ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
2135+
Utils::ApiCheck(index >= 0 && index < array->length(),
2136+
"v8::PrimitiveArray::Set",
2137+
"index must be greater than or equal to 0 and less than the "
2138+
"array length");
2139+
i::Handle<i::Object> i_item = Utils::OpenHandle(*item);
2140+
array->set(index, *i_item);
2141+
}
2142+
2143+
Local<Primitive> PrimitiveArray::Get(int index) {
2144+
i::Handle<i::FixedArray> array = Utils::OpenHandle(this);
2145+
i::Isolate* isolate = array->GetIsolate();
2146+
ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
2147+
Utils::ApiCheck(index >= 0 && index < array->length(),
2148+
"v8::PrimitiveArray::Get",
2149+
"index must be greater than or equal to 0 and less than the "
2150+
"array length");
2151+
i::Handle<i::Object> i_item(array->get(index), isolate);
2152+
return ToApiHandle<Primitive>(i_item);
2153+
}
20922154

20932155
Module::Status Module::GetStatus() const {
20942156
i::Handle<i::Module> self = Utils::OpenHandle(this);
@@ -2225,11 +2287,18 @@ MaybeLocal<UnboundScript> ScriptCompiler::CompileUnboundInternal(
22252287
TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("v8.compile"), "V8.CompileScript");
22262288
i::Handle<i::Object> name_obj;
22272289
i::Handle<i::Object> source_map_url;
2290+
// Backed out for ABI compatibility with V8 6.2
2291+
// i::Handle<i::FixedArray> host_defined_options =
2292+
// isolate->factory()->empty_fixed_array();
22282293
int line_offset = 0;
22292294
int column_offset = 0;
22302295
if (!source->resource_name.IsEmpty()) {
22312296
name_obj = Utils::OpenHandle(*(source->resource_name));
22322297
}
2298+
// Backed out for ABI compatibility with V8 6.2
2299+
// if (!source->host_defined_options.IsEmpty()) {
2300+
// host_defined_options = Utils::OpenHandle(*(source->host_defined_options));
2301+
// }
22332302
if (!source->resource_line_offset.IsEmpty()) {
22342303
line_offset = static_cast<int>(source->resource_line_offset->Value());
22352304
}
@@ -2243,7 +2312,7 @@ MaybeLocal<UnboundScript> ScriptCompiler::CompileUnboundInternal(
22432312
result = i::Compiler::GetSharedFunctionInfoForScript(
22442313
str, name_obj, line_offset, column_offset, source->resource_options,
22452314
source_map_url, isolate->native_context(), NULL, &script_data, options,
2246-
i::NOT_NATIVES_CODE);
2315+
i::NOT_NATIVES_CODE /*, host_defined_options */);
22472316
has_pending_exception = result.is_null();
22482317
if (has_pending_exception && script_data != NULL) {
22492318
// This case won't happen during normal operation; we have compiled
@@ -2508,6 +2577,10 @@ MaybeLocal<Script> ScriptCompiler::Compile(Local<Context> context,
25082577
if (!origin.ResourceName().IsEmpty()) {
25092578
script->set_name(*Utils::OpenHandle(*(origin.ResourceName())));
25102579
}
2580+
// if (!origin.HostDefinedOptions().IsEmpty()) {
2581+
// script->set_host_defined_options(
2582+
// *Utils::OpenHandle(*(origin.HostDefinedOptions())));
2583+
// }
25112584
if (!origin.ResourceLineOffset().IsEmpty()) {
25122585
script->set_line_offset(
25132586
static_cast<int>(origin.ResourceLineOffset()->Value()));
@@ -9828,7 +9901,9 @@ MaybeLocal<UnboundScript> debug::CompileInspectorScript(Isolate* v8_isolate,
98289901
i::Handle<i::Object>(), isolate->native_context(), NULL, &script_data,
98299902
ScriptCompiler::kNoCompileOptions,
98309903
i::FLAG_expose_inspector_scripts ? i::NOT_NATIVES_CODE
9831-
: i::INSPECTOR_CODE);
9904+
: i::INSPECTOR_CODE /*,
9905+
// Backed out for ABI compatibility with V8 6.2
9906+
i::Handle<i::FixedArray>() */);
98329907
has_pending_exception = result.is_null();
98339908
RETURN_ON_FAILED_EXECUTION(UnboundScript);
98349909
}

deps/v8/src/api.h

+13-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,10 @@ class RegisteredExtension {
111111
V(NativeWeakMap, JSWeakMap) \
112112
V(debug::GeneratorObject, JSGeneratorObject) \
113113
V(debug::Script, Script) \
114-
V(Promise, JSPromise)
114+
V(Promise, JSPromise) \
115+
V(Primitive, Object) \
116+
V(PrimitiveArray, FixedArray) \
117+
V(ScriptOrModule, Script)
115118

116119
class Utils {
117120
public:
@@ -209,6 +212,12 @@ class Utils {
209212
v8::internal::Handle<v8::internal::JSWeakMap> obj);
210213
static inline Local<Function> CallableToLocal(
211214
v8::internal::Handle<v8::internal::JSReceiver> obj);
215+
static inline Local<Primitive> ToLocalPrimitive(
216+
v8::internal::Handle<v8::internal::Object> obj);
217+
static inline Local<PrimitiveArray> ToLocal(
218+
v8::internal::Handle<v8::internal::FixedArray> obj);
219+
static inline Local<ScriptOrModule> ScriptOrModuleToLocal(
220+
v8::internal::Handle<v8::internal::Script> obj);
212221

213222
#define DECLARE_OPEN_HANDLE(From, To) \
214223
static inline v8::internal::Handle<v8::internal::To> \
@@ -325,6 +334,9 @@ MAKE_TO_LOCAL(Uint32ToLocal, Object, Uint32)
325334
MAKE_TO_LOCAL(ExternalToLocal, JSObject, External)
326335
MAKE_TO_LOCAL(NativeWeakMapToLocal, JSWeakMap, NativeWeakMap)
327336
MAKE_TO_LOCAL(CallableToLocal, JSReceiver, Function)
337+
MAKE_TO_LOCAL(ToLocalPrimitive, Object, Primitive)
338+
MAKE_TO_LOCAL(ToLocal, FixedArray, PrimitiveArray)
339+
MAKE_TO_LOCAL(ScriptOrModuleToLocal, Script, ScriptOrModule)
328340

329341
#undef MAKE_TO_LOCAL_TYPED_ARRAY
330342
#undef MAKE_TO_LOCAL

deps/v8/src/bootstrapper.cc

+4
Original file line numberDiff line numberDiff line change
@@ -3540,6 +3540,8 @@ bool Bootstrapper::CompileNative(Isolate* isolate, Vector<const char> name,
35403540
Compiler::GetSharedFunctionInfoForScript(
35413541
source, script_name, 0, 0, ScriptOriginOptions(), Handle<Object>(),
35423542
context, NULL, NULL, ScriptCompiler::kNoCompileOptions, natives_flag);
3543+
// Backed out for ABI compatibility with V8 6.2
3544+
// Handle<FixedArray>());
35433545
if (function_info.is_null()) return false;
35443546

35453547
DCHECK(context->IsNativeContext());
@@ -3602,6 +3604,8 @@ bool Genesis::CompileExtension(Isolate* isolate, v8::Extension* extension) {
36023604
function_info = Compiler::GetSharedFunctionInfoForScript(
36033605
source, script_name, 0, 0, ScriptOriginOptions(), Handle<Object>(),
36043606
context, extension, NULL, ScriptCompiler::kNoCompileOptions,
3607+
// Backed out for ABI compatibility with V8 6.2
3608+
// EXTENSION_CODE, Handle<FixedArray>());
36053609
EXTENSION_CODE);
36063610
if (function_info.is_null()) return false;
36073611
cache->Add(name, function_info);

deps/v8/src/compiler.cc

+7
Original file line numberDiff line numberDiff line change
@@ -1192,6 +1192,9 @@ Handle<SharedFunctionInfo> Compiler::GetSharedFunctionInfoForScript(
11921192
int column_offset, ScriptOriginOptions resource_options,
11931193
Handle<Object> source_map_url, Handle<Context> context,
11941194
v8::Extension* extension, ScriptData** cached_data,
1195+
// Backed out for ABI compatibility with V8 6.2
1196+
// ScriptCompiler::CompileOptions compile_options, NativesFlag natives,
1197+
// Handle<FixedArray> host_defined_options) {
11951198
ScriptCompiler::CompileOptions compile_options, NativesFlag natives) {
11961199
Isolate* isolate = source->GetIsolate();
11971200
if (compile_options == ScriptCompiler::kNoCompileOptions) {
@@ -1288,6 +1291,10 @@ Handle<SharedFunctionInfo> Compiler::GetSharedFunctionInfoForScript(
12881291
if (!source_map_url.is_null()) {
12891292
script->set_source_mapping_url(*source_map_url);
12901293
}
1294+
// Backed out for ABI compatibility with V8 6.2
1295+
// if (!host_defined_options.is_null()) {
1296+
// script->set_host_defined_options(*host_defined_options);
1297+
// }
12911298

12921299
// Compile the function and add it to the cache.
12931300
ParseInfo parse_info(script);

deps/v8/src/compiler.h

+2
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,8 @@ class V8_EXPORT_PRIVATE Compiler : public AllStatic {
114114
v8::Extension* extension, ScriptData** cached_data,
115115
ScriptCompiler::CompileOptions compile_options,
116116
NativesFlag is_natives_code);
117+
// Backed out for ABI compatibility with V8 6.2
118+
// NativesFlag is_natives_code, Handle<FixedArray> host_defined_options);
117119

118120
// Create a shared function info object for a Script that has already been
119121
// parsed while the script was being loaded from a streamed source.

0 commit comments

Comments
 (0)