Commit c7c2bafb authored by Yuki Shiino's avatar Yuki Shiino Committed by Commit Bot

bind-gen: Fix a crash issue at named constructors

Since we cannot create an appropriate named constructor when a
context is detached, returns ES undefined as a compromise.

Bug: 839389, 1112227
Change-Id: I529962c80620ba431c87c71936fbcd7d016db225
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2339234Reviewed-by: default avatarHitoshi Yoshida <peria@chromium.org>
Commit-Queue: Yuki Shiino <yukishiino@chromium.org>
Cr-Commit-Position: refs/heads/master@{#795028}
parent 8a8a2fa2
...@@ -251,7 +251,7 @@ ExecutionContext* ExecutionContextFromV8Wrappable(const DOMParser* parser) { ...@@ -251,7 +251,7 @@ ExecutionContext* ExecutionContextFromV8Wrappable(const DOMParser* parser) {
return parser->GetWindow(); return parser->GetWindow();
} }
v8::MaybeLocal<v8::Function> CreateNamedConstructorFunction( v8::MaybeLocal<v8::Value> CreateNamedConstructorFunction(
ScriptState* script_state, ScriptState* script_state,
v8::FunctionCallback callback, v8::FunctionCallback callback,
const char* func_name, const char* func_name,
...@@ -262,6 +262,10 @@ v8::MaybeLocal<v8::Function> CreateNamedConstructorFunction( ...@@ -262,6 +262,10 @@ v8::MaybeLocal<v8::Function> CreateNamedConstructorFunction(
V8PerIsolateData* per_isolate_data = V8PerIsolateData::From(isolate); V8PerIsolateData* per_isolate_data = V8PerIsolateData::From(isolate);
const void* callback_key = reinterpret_cast<const void*>(callback); const void* callback_key = reinterpret_cast<const void*>(callback);
if (!script_state->ContextIsValid()) {
return v8::Undefined(isolate);
}
// Named constructors are not interface objcets (despite that they're // Named constructors are not interface objcets (despite that they're
// pretending so), but we reuse the cache of interface objects, which just // pretending so), but we reuse the cache of interface objects, which just
// works because both are V8 function template. // works because both are V8 function template.
...@@ -286,7 +290,7 @@ v8::MaybeLocal<v8::Function> CreateNamedConstructorFunction( ...@@ -286,7 +290,7 @@ v8::MaybeLocal<v8::Function> CreateNamedConstructorFunction(
V8PerContextData* per_context_data = V8PerContextData::From(context); V8PerContextData* per_context_data = V8PerContextData::From(context);
v8::Local<v8::Function> function; v8::Local<v8::Function> function;
if (!function_template->GetFunction(context).ToLocal(&function)) { if (!function_template->GetFunction(context).ToLocal(&function)) {
return v8::MaybeLocal<v8::Function>(); return v8::MaybeLocal<v8::Value>();
} }
v8::Local<v8::Object> prototype_object = v8::Local<v8::Object> prototype_object =
per_context_data->PrototypeForType(wrapper_type_info); per_context_data->PrototypeForType(wrapper_type_info);
...@@ -297,7 +301,7 @@ v8::MaybeLocal<v8::Function> CreateNamedConstructorFunction( ...@@ -297,7 +301,7 @@ v8::MaybeLocal<v8::Function> CreateNamedConstructorFunction(
static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontEnum | static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontEnum |
v8::DontDelete)) v8::DontDelete))
.To(&did_define)) { .To(&did_define)) {
return v8::MaybeLocal<v8::Function>(); return v8::MaybeLocal<v8::Value>();
} }
CHECK(did_define); CHECK(did_define);
return function; return function;
......
...@@ -168,7 +168,7 @@ CORE_EXPORT ExecutionContext* ExecutionContextFromV8Wrappable( ...@@ -168,7 +168,7 @@ CORE_EXPORT ExecutionContext* ExecutionContextFromV8Wrappable(
CORE_EXPORT ExecutionContext* ExecutionContextFromV8Wrappable( CORE_EXPORT ExecutionContext* ExecutionContextFromV8Wrappable(
const DOMParser* parser); const DOMParser* parser);
CORE_EXPORT v8::MaybeLocal<v8::Function> CreateNamedConstructorFunction( CORE_EXPORT v8::MaybeLocal<v8::Value> CreateNamedConstructorFunction(
ScriptState* script_state, ScriptState* script_state,
v8::FunctionCallback callback, v8::FunctionCallback callback,
const char* func_name, const char* func_name,
......
...@@ -2068,17 +2068,17 @@ if (!v8_named_constructor->IsUndefined()) { ...@@ -2068,17 +2068,17 @@ if (!v8_named_constructor->IsUndefined()) {
""" """
pattern = """\ pattern = """\
v8::Local<v8::Function> v8_function; v8::Local<v8::Value> v8_value;
if (!bindings::CreateNamedConstructorFunction( if (!bindings::CreateNamedConstructorFunction(
${script_state}, ${script_state},
{callback}, {callback},
"{func_name}", "{func_name}",
{func_length}, {func_length},
{v8_bridge}::GetWrapperTypeInfo()) {v8_bridge}::GetWrapperTypeInfo())
.ToLocal(&v8_function)) { .ToLocal(&v8_value)) {
return; return;
} }
bindings::V8SetReturnValue(${info}, v8_function); bindings::V8SetReturnValue(${info}, v8_value);
""" """
create_named_constructor_function = _format( create_named_constructor_function = _format(
pattern, pattern,
...@@ -2088,7 +2088,7 @@ bindings::V8SetReturnValue(${info}, v8_function); ...@@ -2088,7 +2088,7 @@ bindings::V8SetReturnValue(${info}, v8_function);
v8_bridge=named_ctor_v8_bridge) v8_bridge=named_ctor_v8_bridge)
return_value_cache_update_value = """\ return_value_cache_update_value = """\
v8_private_named_constructor.Set(${v8_receiver}, v8_function); v8_private_named_constructor.Set(${v8_receiver}, v8_value);
""" """
body.extend([ body.extend([
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment