Skip to content

Commit 1fe426c

Browse files
devsnektargos
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 <neis@chromium.org> Commit-Queue: Georg Neis <neis@chromium.org> Cr-Commit-Position: refs/heads/master@{nodejs#52597} Refs: v8/v8@39d546a PR-URL: nodejs#20016 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Guy Bedford <guybedford@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
1 parent 63aa6b6 commit 1fe426c

5 files changed

Lines changed: 40 additions & 1 deletion

File tree

‎common.gypi‎

Lines changed: 1 addition & 1 deletion
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‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ Felix Geisendörfer <haimuiba@gmail.com>
7070
Filipe David Manana <fdmanana@gmail.com>
7171
Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
7272
Geoffrey Garside <ggarside@gmail.com>
73+
Gus Caplan <me@gus.host>
7374
Gwang Yoon Hwang <ryumiel@company100.net>
7475
Henrique Ferreiro <henrique.ferreiro@gmail.com>
7576
Hirofumi Mako <mkhrfm@gmail.com>

‎deps/v8/include/v8.h‎

Lines changed: 5 additions & 0 deletions
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‎

Lines changed: 4 additions & 0 deletions
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‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27239,6 +27239,35 @@ TEST(ImportMeta) {
2723927239
CHECK(result->StrictEquals(Local<v8::Value>::Cast(v8::Utils::ToLocal(meta))));
2724027240
}
2724127241

27242+
TEST(GetModuleNamespace) {
27243+
LocalContext context;
27244+
v8::Isolate* isolate = context->GetIsolate();
27245+
v8::HandleScope scope(isolate);
27246+
27247+
Local<String> url = v8_str("www.google.com");
27248+
Local<String> source_text = v8_str("export default 5; export const a = 10;");
27249+
v8::ScriptOrigin origin(url, Local<v8::Integer>(), Local<v8::Integer>(),
27250+
Local<v8::Boolean>(), Local<v8::Integer>(),
27251+
Local<v8::Value>(), Local<v8::Boolean>(),
27252+
Local<v8::Boolean>(), True(isolate));
27253+
v8::ScriptCompiler::Source source(source_text, origin);
27254+
Local<Module> module =
27255+
v8::ScriptCompiler::CompileModule(isolate, &source).ToLocalChecked();
27256+
module->InstantiateModule(context.local(), UnexpectedModuleResolveCallback)
27257+
.ToChecked();
27258+
module->Evaluate(context.local()).ToLocalChecked();
27259+
27260+
Local<Value> ns_val = module->GetModuleNamespace();
27261+
CHECK(ns_val->IsModuleNamespaceObject());
27262+
Local<Object> ns = ns_val.As<Object>();
27263+
CHECK(ns->Get(context.local(), v8_str("default"))
27264+
.ToLocalChecked()
27265+
->StrictEquals(v8::Number::New(isolate, 5)));
27266+
CHECK(ns->Get(context.local(), v8_str("a"))
27267+
.ToLocalChecked()
27268+
->StrictEquals(v8::Number::New(isolate, 10)));
27269+
}
27270+
2724227271
TEST(GlobalTemplateWithDoubleProperty) {
2724327272
v8::Isolate* isolate = CcTest::isolate();
2724427273
v8::HandleScope handle_scope(isolate);

0 commit comments

Comments
 (0)