Commit 09060f57 authored by Jeremy Roman's avatar Jeremy Roman Committed by Commit Bot

bindings: Drop use of V8CallBoolean in generated dictionary code in favor of a...

bindings: Drop use of V8CallBoolean in generated dictionary code in favor of a lambda that uses v8::MaybeLocal::To.

Bug: 670615
Change-Id: Ib4f1b5674cec44a328b484510b4b197b2afec21d
Reviewed-on: https://chromium-review.googlesource.com/c/1281087
Commit-Queue: Jeremy Roman <jbroman@chromium.org>
Reviewed-by: default avatarYuki Shiino <yukishiino@chromium.org>
Reviewed-by: default avatarHitoshi Yoshida <peria@chromium.org>
Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Cr-Commit-Position: refs/heads/master@{#600369}
parent dc201a7e
...@@ -128,6 +128,18 @@ bool toV8{{cpp_class}}(const {{cpp_class}}& impl, v8::Local<v8::Object> dictiona ...@@ -128,6 +128,18 @@ bool toV8{{cpp_class}}(const {{cpp_class}}& impl, v8::Local<v8::Object> dictiona
{% if members %} {% if members %}
const v8::Eternal<v8::Name>* keys = eternal{{v8_class}}Keys(isolate); const v8::Eternal<v8::Name>* keys = eternal{{v8_class}}Keys(isolate);
v8::Local<v8::Context> context = isolate->GetCurrentContext(); v8::Local<v8::Context> context = isolate->GetCurrentContext();
auto create_property = [dictionary, context, keys, isolate](
size_t key_index, v8::Local<v8::Value> value) {
bool added_property;
v8::Local<v8::Name> key = keys[key_index].Get(isolate);
if (!dictionary->CreateDataProperty(context, key, value)
.To(&added_property)) {
return false;
}
return added_property;
};
{% if has_origin_trial_members %} {% if has_origin_trial_members %}
ExecutionContext* executionContext = ToExecutionContext(context); ExecutionContext* executionContext = ToExecutionContext(context);
DCHECK(executionContext); DCHECK(executionContext);
...@@ -164,7 +176,7 @@ bool toV8{{cpp_class}}(const {{cpp_class}}& impl, v8::Local<v8::Object> dictiona ...@@ -164,7 +176,7 @@ bool toV8{{cpp_class}}(const {{cpp_class}}& impl, v8::Local<v8::Object> dictiona
If there is not, then the compiler will inline this call into the only branch that sets it to true. If there is not, then the compiler will inline this call into the only branch that sets it to true.
Either way, the code is efficient and the variable is completely elided. #} Either way, the code is efficient and the variable is completely elided. #}
if ({{member.has_value_or_default}} && if ({{member.has_value_or_default}} &&
!V8CallBoolean(dictionary->CreateDataProperty(context, keys[{{members.index(member)}}].Get(isolate), {{member.v8_value}}))) { !create_property({{members.index(member)}}, {{member.v8_value}})) {
return false; return false;
} }
......
...@@ -119,6 +119,18 @@ bool toV8TestDictionaryDerivedImplementedAs(const TestDictionaryDerivedImplement ...@@ -119,6 +119,18 @@ bool toV8TestDictionaryDerivedImplementedAs(const TestDictionaryDerivedImplement
const v8::Eternal<v8::Name>* keys = eternalV8TestDictionaryDerivedImplementedAsKeys(isolate); const v8::Eternal<v8::Name>* keys = eternalV8TestDictionaryDerivedImplementedAsKeys(isolate);
v8::Local<v8::Context> context = isolate->GetCurrentContext(); v8::Local<v8::Context> context = isolate->GetCurrentContext();
auto create_property = [dictionary, context, keys, isolate](
size_t key_index, v8::Local<v8::Value> value) {
bool added_property;
v8::Local<v8::Name> key = keys[key_index].Get(isolate);
if (!dictionary->CreateDataProperty(context, key, value)
.To(&added_property)) {
return false;
}
return added_property;
};
v8::Local<v8::Value> derived_string_member_value; v8::Local<v8::Value> derived_string_member_value;
bool derived_string_member_has_value_or_default = false; bool derived_string_member_has_value_or_default = false;
if (impl.hasDerivedStringMember()) { if (impl.hasDerivedStringMember()) {
...@@ -126,7 +138,7 @@ bool toV8TestDictionaryDerivedImplementedAs(const TestDictionaryDerivedImplement ...@@ -126,7 +138,7 @@ bool toV8TestDictionaryDerivedImplementedAs(const TestDictionaryDerivedImplement
derived_string_member_has_value_or_default = true; derived_string_member_has_value_or_default = true;
} }
if (derived_string_member_has_value_or_default && if (derived_string_member_has_value_or_default &&
!V8CallBoolean(dictionary->CreateDataProperty(context, keys[0].Get(isolate), derived_string_member_value))) { !create_property(0, derived_string_member_value)) {
return false; return false;
} }
...@@ -140,7 +152,7 @@ bool toV8TestDictionaryDerivedImplementedAs(const TestDictionaryDerivedImplement ...@@ -140,7 +152,7 @@ bool toV8TestDictionaryDerivedImplementedAs(const TestDictionaryDerivedImplement
derived_string_member_with_default_has_value_or_default = true; derived_string_member_with_default_has_value_or_default = true;
} }
if (derived_string_member_with_default_has_value_or_default && if (derived_string_member_with_default_has_value_or_default &&
!V8CallBoolean(dictionary->CreateDataProperty(context, keys[1].Get(isolate), derived_string_member_with_default_value))) { !create_property(1, derived_string_member_with_default_value)) {
return false; return false;
} }
...@@ -153,7 +165,7 @@ bool toV8TestDictionaryDerivedImplementedAs(const TestDictionaryDerivedImplement ...@@ -153,7 +165,7 @@ bool toV8TestDictionaryDerivedImplementedAs(const TestDictionaryDerivedImplement
NOTREACHED(); NOTREACHED();
} }
if (required_long_member_has_value_or_default && if (required_long_member_has_value_or_default &&
!V8CallBoolean(dictionary->CreateDataProperty(context, keys[2].Get(isolate), required_long_member_value))) { !create_property(2, required_long_member_value)) {
return false; return false;
} }
...@@ -164,7 +176,7 @@ bool toV8TestDictionaryDerivedImplementedAs(const TestDictionaryDerivedImplement ...@@ -164,7 +176,7 @@ bool toV8TestDictionaryDerivedImplementedAs(const TestDictionaryDerivedImplement
string_or_double_sequence_member_has_value_or_default = true; string_or_double_sequence_member_has_value_or_default = true;
} }
if (string_or_double_sequence_member_has_value_or_default && if (string_or_double_sequence_member_has_value_or_default &&
!V8CallBoolean(dictionary->CreateDataProperty(context, keys[3].Get(isolate), string_or_double_sequence_member_value))) { !create_property(3, string_or_double_sequence_member_value)) {
return false; return false;
} }
......
...@@ -72,6 +72,18 @@ bool toV8TestInterfaceEventInit(const TestInterfaceEventInit& impl, v8::Local<v8 ...@@ -72,6 +72,18 @@ bool toV8TestInterfaceEventInit(const TestInterfaceEventInit& impl, v8::Local<v8
const v8::Eternal<v8::Name>* keys = eternalV8TestInterfaceEventInitKeys(isolate); const v8::Eternal<v8::Name>* keys = eternalV8TestInterfaceEventInitKeys(isolate);
v8::Local<v8::Context> context = isolate->GetCurrentContext(); v8::Local<v8::Context> context = isolate->GetCurrentContext();
auto create_property = [dictionary, context, keys, isolate](
size_t key_index, v8::Local<v8::Value> value) {
bool added_property;
v8::Local<v8::Name> key = keys[key_index].Get(isolate);
if (!dictionary->CreateDataProperty(context, key, value)
.To(&added_property)) {
return false;
}
return added_property;
};
v8::Local<v8::Value> string_member_value; v8::Local<v8::Value> string_member_value;
bool string_member_has_value_or_default = false; bool string_member_has_value_or_default = false;
if (impl.hasStringMember()) { if (impl.hasStringMember()) {
...@@ -79,7 +91,7 @@ bool toV8TestInterfaceEventInit(const TestInterfaceEventInit& impl, v8::Local<v8 ...@@ -79,7 +91,7 @@ bool toV8TestInterfaceEventInit(const TestInterfaceEventInit& impl, v8::Local<v8
string_member_has_value_or_default = true; string_member_has_value_or_default = true;
} }
if (string_member_has_value_or_default && if (string_member_has_value_or_default &&
!V8CallBoolean(dictionary->CreateDataProperty(context, keys[0].Get(isolate), string_member_value))) { !create_property(0, string_member_value)) {
return false; return false;
} }
......
...@@ -64,6 +64,18 @@ v8::Local<v8::Value> TestPermissiveDictionary::ToV8Impl(v8::Local<v8::Object> cr ...@@ -64,6 +64,18 @@ v8::Local<v8::Value> TestPermissiveDictionary::ToV8Impl(v8::Local<v8::Object> cr
bool toV8TestPermissiveDictionary(const TestPermissiveDictionary& impl, v8::Local<v8::Object> dictionary, v8::Local<v8::Object> creationContext, v8::Isolate* isolate) { bool toV8TestPermissiveDictionary(const TestPermissiveDictionary& impl, v8::Local<v8::Object> dictionary, v8::Local<v8::Object> creationContext, v8::Isolate* isolate) {
const v8::Eternal<v8::Name>* keys = eternalV8TestPermissiveDictionaryKeys(isolate); const v8::Eternal<v8::Name>* keys = eternalV8TestPermissiveDictionaryKeys(isolate);
v8::Local<v8::Context> context = isolate->GetCurrentContext(); v8::Local<v8::Context> context = isolate->GetCurrentContext();
auto create_property = [dictionary, context, keys, isolate](
size_t key_index, v8::Local<v8::Value> value) {
bool added_property;
v8::Local<v8::Name> key = keys[key_index].Get(isolate);
if (!dictionary->CreateDataProperty(context, key, value)
.To(&added_property)) {
return false;
}
return added_property;
};
v8::Local<v8::Value> boolean_member_value; v8::Local<v8::Value> boolean_member_value;
bool boolean_member_has_value_or_default = false; bool boolean_member_has_value_or_default = false;
if (impl.hasBooleanMember()) { if (impl.hasBooleanMember()) {
...@@ -71,7 +83,7 @@ bool toV8TestPermissiveDictionary(const TestPermissiveDictionary& impl, v8::Loca ...@@ -71,7 +83,7 @@ bool toV8TestPermissiveDictionary(const TestPermissiveDictionary& impl, v8::Loca
boolean_member_has_value_or_default = true; boolean_member_has_value_or_default = true;
} }
if (boolean_member_has_value_or_default && if (boolean_member_has_value_or_default &&
!V8CallBoolean(dictionary->CreateDataProperty(context, keys[0].Get(isolate), boolean_member_value))) { !create_property(0, boolean_member_value)) {
return false; return false;
} }
......
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