Skip to content

Commit f7cc975

Browse files
devsnekMylesBorins
authored andcommitted
deps: cherry-pick 39d546a from upstream V8
Original commit message: [api] introduce v8::Value::IsModuleNamespaceObject This allows an embedder to check if a Value is a module namespace object. Cq-Include-Trybots: luci.chromium.try:linux_chromium_rel_ng Change-Id: Idffceff451dd5f5c6a53d4cb3ce02c1c2c5b653c Reviewed-on: https://chromium-review.googlesource.com/1011762 Reviewed-by: Georg Neis <[email protected]> Commit-Queue: Georg Neis <[email protected]> Cr-Commit-Position: refs/heads/master@{#52597} Refs: v8/v8@39d546a PR-URL: #20016 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Guy Bedford <[email protected]> Reviewed-By: Colin Ihrig <[email protected]>
1 parent 547acf9 commit f7cc975

File tree

5 files changed

+40
-1
lines changed

5 files changed

+40
-1
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.1',
30+
'v8_embedder_string': '-node.2',
3131

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

deps/v8/AUTHORS

+1
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ Felix Geisendörfer <[email protected]>
7070
Filipe David Manana <[email protected]>
7171
Franziska Hinkelmann <[email protected]>
7272
Geoffrey Garside <[email protected]>
73+
Gus Caplan <[email protected]>
7374
Gwang Yoon Hwang <[email protected]>
7475
Henrique Ferreiro <[email protected]>
7576
Hirofumi Mako <[email protected]>

deps/v8/include/v8.h

+5
Original file line numberDiff line numberDiff line change
@@ -2378,6 +2378,11 @@ class V8_EXPORT Value : public Data {
23782378

23792379
bool IsWebAssemblyCompiledModule() const;
23802380

2381+
/**
2382+
* Returns true if the value is a Module Namespace Object.
2383+
*/
2384+
bool IsModuleNamespaceObject() const;
2385+
23812386
V8_WARN_UNUSED_RESULT MaybeLocal<BigInt> ToBigInt(
23822387
Local<Context> context) const;
23832388
V8_WARN_UNUSED_RESULT MaybeLocal<Boolean> ToBoolean(

deps/v8/src/api.cc

+4
Original file line numberDiff line numberDiff line change
@@ -3583,6 +3583,10 @@ bool Value::IsSetIterator() const {
35833583

35843584
bool Value::IsPromise() const { return Utils::OpenHandle(this)->IsJSPromise(); }
35853585

3586+
bool Value::IsModuleNamespaceObject() const {
3587+
return Utils::OpenHandle(this)->IsJSModuleNamespace();
3588+
}
3589+
35863590
MaybeLocal<String> Value::ToString(Local<Context> context) const {
35873591
auto obj = Utils::OpenHandle(this);
35883592
if (obj->IsString()) return ToApiHandle<String>(obj);

deps/v8/test/cctest/test-api.cc

+29
Original file line numberDiff line numberDiff line change
@@ -27274,6 +27274,35 @@ TEST(ImportMeta) {
2727427274
CHECK(result->StrictEquals(Local<v8::Value>::Cast(v8::Utils::ToLocal(meta))));
2727527275
}
2727627276

27277+
TEST(GetModuleNamespace) {
27278+
LocalContext context;
27279+
v8::Isolate* isolate = context->GetIsolate();
27280+
v8::HandleScope scope(isolate);
27281+
27282+
Local<String> url = v8_str("www.google.com");
27283+
Local<String> source_text = v8_str("export default 5; export const a = 10;");
27284+
v8::ScriptOrigin origin(url, Local<v8::Integer>(), Local<v8::Integer>(),
27285+
Local<v8::Boolean>(), Local<v8::Integer>(),
27286+
Local<v8::Value>(), Local<v8::Boolean>(),
27287+
Local<v8::Boolean>(), True(isolate));
27288+
v8::ScriptCompiler::Source source(source_text, origin);
27289+
Local<Module> module =
27290+
v8::ScriptCompiler::CompileModule(isolate, &source).ToLocalChecked();
27291+
module->InstantiateModule(context.local(), UnexpectedModuleResolveCallback)
27292+
.ToChecked();
27293+
module->Evaluate(context.local()).ToLocalChecked();
27294+
27295+
Local<Value> ns_val = module->GetModuleNamespace();
27296+
CHECK(ns_val->IsModuleNamespaceObject());
27297+
Local<Object> ns = ns_val.As<Object>();
27298+
CHECK(ns->Get(context.local(), v8_str("default"))
27299+
.ToLocalChecked()
27300+
->StrictEquals(v8::Number::New(isolate, 5)));
27301+
CHECK(ns->Get(context.local(), v8_str("a"))
27302+
.ToLocalChecked()
27303+
->StrictEquals(v8::Number::New(isolate, 10)));
27304+
}
27305+
2727727306
TEST(GlobalTemplateWithDoubleProperty) {
2727827307
v8::Isolate* isolate = CcTest::isolate();
2727927308
v8::HandleScope handle_scope(isolate);

0 commit comments

Comments
 (0)