Skip to content

Commit

Permalink
deps: cherry-pick 39d546a from upstream V8
Browse files Browse the repository at this point in the history
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@{#52597}

Refs: v8/v8@39d546a

PR-URL: #20016
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Guy Bedford <guybedford@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
  • Loading branch information
devsnek authored and jasnell committed Apr 16, 2018
1 parent 8a0b994 commit 5303a50
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 0 deletions.
1 change: 1 addition & 0 deletions deps/v8/AUTHORS
Expand Up @@ -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>
Expand Down
5 changes: 5 additions & 0 deletions deps/v8/include/v8.h
Expand Up @@ -2354,6 +2354,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<Boolean> ToBoolean(
Local<Context> context) const;
V8_WARN_UNUSED_RESULT MaybeLocal<Number> ToNumber(
Expand Down
4 changes: 4 additions & 0 deletions deps/v8/src/api.cc
Expand Up @@ -3584,6 +3584,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);
Expand Down
29 changes: 29 additions & 0 deletions deps/v8/test/cctest/test-api.cc
Expand Up @@ -27041,6 +27041,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);
Expand Down

0 comments on commit 5303a50

Please sign in to comment.