Commit e10a4e90 authored by Keishi Hattori's avatar Keishi Hattori Committed by Commit Bot

Forbid passing empty v8::Local to ScriptValue constructor

Forbid passing empty v8::Local to ScriptValue constructor.
This will make the rules consistent with WorldSafeV8Reference's constructor.

Change-Id: Id0f0302025eb8397a5ebcef78ea91671cda1e453
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1847412
Commit-Queue: Keishi Hattori <keishi@chromium.org>
Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Reviewed-by: default avatarYuki Shiino <yukishiino@chromium.org>
Cr-Commit-Position: refs/heads/master@{#704136}
parent ee6039d7
......@@ -70,14 +70,10 @@ class CORE_EXPORT ScriptValue final {
ScriptValue() = default;
// TODO(rikaf): Forbid passing empty v8::Local<v8::Value> to ScriptValue's
// ctor.
ScriptValue(v8::Isolate* isolate, v8::Local<v8::Value> value)
: isolate_(isolate),
value_(value.IsEmpty()
? MakeGarbageCollected<WorldSafeV8ReferenceWrapper>()
: MakeGarbageCollected<WorldSafeV8ReferenceWrapper>(isolate,
value)) {
value_(
MakeGarbageCollected<WorldSafeV8ReferenceWrapper>(isolate, value)) {
DCHECK(isolate_);
}
......
......@@ -77,8 +77,10 @@ inline v8::Local<v8::Value> ToV8(const DisallowNewWrapper<ScriptValue>* value,
// and ScriptValue
template <typename T>
inline ScriptValue ScriptValue::From(ScriptState* script_state, T&& value) {
return ScriptValue(script_state->GetIsolate(),
ToV8(std::forward<T>(value), script_state));
v8::Local<v8::Value> v8_value = ToV8(std::forward<T>(value), script_state);
if (v8_value.IsEmpty())
return ScriptValue();
return ScriptValue(script_state->GetIsolate(), v8_value);
}
} // namespace blink
......
......@@ -59,6 +59,7 @@ class WorldSafeV8Reference final {
explicit WorldSafeV8Reference(v8::Isolate* isolate, v8::Local<V8Type> value)
: v8_reference_(isolate, value) {
DCHECK(!value.IsEmpty());
// Basically, |world_| is a world when this V8 reference is created.
// However, when this V8 reference isn't created in context and value is
// object, we set |world_| to a value's creation cotext's world.
......
......@@ -1631,6 +1631,8 @@ ScriptValue Document::registerElement(ScriptState* script_state,
V0CustomElementConstructorBuilder constructor_builder(script_state, options);
RegistrationContext()->RegisterElement(this, &constructor_builder, name,
exception_state);
if (exception_state.HadException())
return ScriptValue();
return constructor_builder.BindingsReturnValue();
}
......
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