85 lines
3.1 KiB
Diff
85 lines
3.1 KiB
Diff
|
39d546a24022b62b00aedf7b556ac6c9e2306aab
|
||
|
diff --git a/AUTHORS b/AUTHORS
|
||
|
index 3251716f2a..4b5163961d 100644
|
||
|
--- a/AUTHORS
|
||
|
+++ b/AUTHORS
|
||
|
@@ -70,6 +70,7 @@ Felix Geisendörfer <haimuiba@gmail.com>
|
||
|
Filipe David Manana <fdmanana@gmail.com>
|
||
|
Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
|
||
|
Geoffrey Garside <ggarside@gmail.com>
|
||
|
+Gus Caplan <me@gus.host>
|
||
|
Gwang Yoon Hwang <ryumiel@company100.net>
|
||
|
Henrique Ferreiro <henrique.ferreiro@gmail.com>
|
||
|
Hirofumi Mako <mkhrfm@gmail.com>
|
||
|
diff --git a/include/v8.h b/include/v8.h
|
||
|
index 573e80176d..aeeebba304 100644
|
||
|
--- a/include/v8.h
|
||
|
+++ b/include/v8.h
|
||
|
@@ -2378,6 +2378,11 @@ class V8_EXPORT Value : public Data {
|
||
|
|
||
|
bool IsWebAssemblyCompiledModule() const;
|
||
|
|
||
|
+ /**
|
||
|
+ * Returns true if the value is a Module Namespace Object.
|
||
|
+ */
|
||
|
+ bool IsModuleNamespaceObject() const;
|
||
|
+
|
||
|
V8_WARN_UNUSED_RESULT MaybeLocal<BigInt> ToBigInt(
|
||
|
Local<Context> context) const;
|
||
|
V8_WARN_UNUSED_RESULT MaybeLocal<Boolean> ToBoolean(
|
||
|
diff --git a/src/api.cc b/src/api.cc
|
||
|
index 8b177d041d..6dd669ee11 100644
|
||
|
--- a/src/api.cc
|
||
|
+++ b/src/api.cc
|
||
|
@@ -3583,6 +3583,10 @@ bool Value::IsSetIterator() const {
|
||
|
|
||
|
bool Value::IsPromise() const { return Utils::OpenHandle(this)->IsJSPromise(); }
|
||
|
|
||
|
+bool Value::IsModuleNamespaceObject() const {
|
||
|
+ return Utils::OpenHandle(this)->IsJSModuleNamespace();
|
||
|
+}
|
||
|
+
|
||
|
MaybeLocal<String> Value::ToString(Local<Context> context) const {
|
||
|
auto obj = Utils::OpenHandle(this);
|
||
|
if (obj->IsString()) return ToApiHandle<String>(obj);
|
||
|
diff --git a/test/cctest/test-api.cc b/test/cctest/test-api.cc
|
||
|
index 54afc61f4c..b7483a7c5e 100644
|
||
|
--- a/test/cctest/test-api.cc
|
||
|
+++ b/test/cctest/test-api.cc
|
||
|
@@ -27239,6 +27239,35 @@ TEST(ImportMeta) {
|
||
|
CHECK(result->StrictEquals(Local<v8::Value>::Cast(v8::Utils::ToLocal(meta))));
|
||
|
}
|
||
|
|
||
|
+TEST(GetModuleNamespace) {
|
||
|
+ LocalContext context;
|
||
|
+ v8::Isolate* isolate = context->GetIsolate();
|
||
|
+ v8::HandleScope scope(isolate);
|
||
|
+
|
||
|
+ Local<String> url = v8_str("www.google.com");
|
||
|
+ Local<String> source_text = v8_str("export default 5; export const a = 10;");
|
||
|
+ v8::ScriptOrigin origin(url, Local<v8::Integer>(), Local<v8::Integer>(),
|
||
|
+ Local<v8::Boolean>(), Local<v8::Integer>(),
|
||
|
+ Local<v8::Value>(), Local<v8::Boolean>(),
|
||
|
+ Local<v8::Boolean>(), True(isolate));
|
||
|
+ v8::ScriptCompiler::Source source(source_text, origin);
|
||
|
+ Local<Module> module =
|
||
|
+ v8::ScriptCompiler::CompileModule(isolate, &source).ToLocalChecked();
|
||
|
+ module->InstantiateModule(context.local(), UnexpectedModuleResolveCallback)
|
||
|
+ .ToChecked();
|
||
|
+ module->Evaluate(context.local()).ToLocalChecked();
|
||
|
+
|
||
|
+ Local<Value> ns_val = module->GetModuleNamespace();
|
||
|
+ CHECK(ns_val->IsModuleNamespaceObject());
|
||
|
+ Local<Object> ns = ns_val.As<Object>();
|
||
|
+ CHECK(ns->Get(context.local(), v8_str("default"))
|
||
|
+ .ToLocalChecked()
|
||
|
+ ->StrictEquals(v8::Number::New(isolate, 5)));
|
||
|
+ CHECK(ns->Get(context.local(), v8_str("a"))
|
||
|
+ .ToLocalChecked()
|
||
|
+ ->StrictEquals(v8::Number::New(isolate, 10)));
|
||
|
+}
|
||
|
+
|
||
|
TEST(GlobalTemplateWithDoubleProperty) {
|
||
|
v8::Isolate* isolate = CcTest::isolate();
|
||
|
v8::HandleScope handle_scope(isolate);
|