Skip to content

Commit f5d7f13

Browse files
devsnekBridgeAR
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 1fdb73e commit f5d7f13

4 files changed

Lines changed: 39 additions & 0 deletions

File tree

deps/v8/AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ Felix Geisendörfer <haimuiba@gmail.com>
6666
Filipe David Manana <fdmanana@gmail.com>
6767
Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
6868
Geoffrey Garside <ggarside@gmail.com>
69+
Gus Caplan <me@gus.host>
6970
Gwang Yoon Hwang <ryumiel@company100.net>
7071
Henrique Ferreiro <henrique.ferreiro@gmail.com>
7172
Hirofumi Mako <mkhrfm@gmail.com>

deps/v8/include/v8.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2345,6 +2345,11 @@ class V8_EXPORT Value : public Data {
23452345

23462346
bool IsWebAssemblyCompiledModule() const;
23472347

2348+
/**
2349+
* Returns true if the value is a Module Namespace Object.
2350+
*/
2351+
bool IsModuleNamespaceObject() const;
2352+
23482353
V8_WARN_UNUSED_RESULT MaybeLocal<Boolean> ToBoolean(
23492354
Local<Context> context) const;
23502355
V8_WARN_UNUSED_RESULT MaybeLocal<Number> ToNumber(

deps/v8/src/api.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3753,6 +3753,10 @@ bool Value::IsSetIterator() const {
37533753

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

3756+
bool Value::IsModuleNamespaceObject() const {
3757+
return Utils::OpenHandle(this)->IsJSModuleNamespace();
3758+
}
3759+
37563760
MaybeLocal<String> Value::ToString(Local<Context> context) const {
37573761
auto obj = Utils::OpenHandle(this);
37583762
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
@@ -27131,6 +27131,35 @@ TEST(DynamicImport) {
2713127131
CHECK(result->Equals(i::String::cast(promise->result())));
2713227132
}
2713327133

27134+
TEST(GetModuleNamespace) {
27135+
LocalContext context;
27136+
v8::Isolate* isolate = context->GetIsolate();
27137+
v8::HandleScope scope(isolate);
27138+
27139+
Local<String> url = v8_str("www.google.com");
27140+
Local<String> source_text = v8_str("export default 5; export const a = 10;");
27141+
v8::ScriptOrigin origin(url, Local<v8::Integer>(), Local<v8::Integer>(),
27142+
Local<v8::Boolean>(), Local<v8::Integer>(),
27143+
Local<v8::Value>(), Local<v8::Boolean>(),
27144+
Local<v8::Boolean>(), True(isolate));
27145+
v8::ScriptCompiler::Source source(source_text, origin);
27146+
Local<Module> module =
27147+
v8::ScriptCompiler::CompileModule(isolate, &source).ToLocalChecked();
27148+
module->InstantiateModule(context.local(), UnexpectedModuleResolveCallback)
27149+
.ToChecked();
27150+
module->Evaluate(context.local()).ToLocalChecked();
27151+
27152+
Local<Value> ns_val = module->GetModuleNamespace();
27153+
CHECK(ns_val->IsModuleNamespaceObject());
27154+
Local<Object> ns = ns_val.As<Object>();
27155+
CHECK(ns->Get(context.local(), v8_str("default"))
27156+
.ToLocalChecked()
27157+
->StrictEquals(v8::Number::New(isolate, 5)));
27158+
CHECK(ns->Get(context.local(), v8_str("a"))
27159+
.ToLocalChecked()
27160+
->StrictEquals(v8::Number::New(isolate, 10)));
27161+
}
27162+
2713427163
TEST(GlobalTemplateWithDoubleProperty) {
2713527164
v8::Isolate* isolate = CcTest::isolate();
2713627165
v8::HandleScope handle_scope(isolate);

0 commit comments

Comments
 (0)