Bindings generator can evaluate value more than once |
||||
Issue description
v8_types.py contains special cases like this:
'SerializedScriptValue': '{cpp_value} ? {cpp_value}->deserialize() : v8::Local<v8::Value>(v8::Null({isolate}))',
{cpp_value} isn't necessarily just a local variable; it can be a function call that isn't free. In these cases it gets evaluated twice in the success case.
For example, in V8Internals.cpp:
v8SetReturnValue(info, impl->deserializeBuffer(buffer) ? impl->deserializeBuffer(buffer)->deserialize() : v8::Local<v8::Value>(v8::Null(info.GetIsolate())));
Here we deserialize the buffer, producing a PassRefPtr<SerializedScriptValue>, and then if if that succeeded, we deserialize it again in order to invoke SerializedScriptValue::deserialize.
We should only do this once, either by using a local variable, or possibly by being clever with a lambda, like:
([](PassRefPtr<SerializedScriptValue> x) { return x ? x->deserialize() : ...; })(impl->deserializeBuffer(buffer));
It looks like there may be other cases where {cpp_value} is evaluated twice, and I'm not sure how the bindings team would prefer to deal with this.
,
Aug 8 2016
,
Aug 10 2016
The following revision refers to this bug: https://chromium.googlesource.com/chromium/src.git/+/400793e57acc5f8b315a27caf44edc1a362d7afc commit 400793e57acc5f8b315a27caf44edc1a362d7afc Author: lkawai <lkawai@google.com> Date: Wed Aug 10 07:36:46 2016 Make a deserializing function In the previous code, a conditional operator was used and {cpp_value} was evaluated twice in the success case. This CL adds a separate function in order to avoid evaluating it twice. BUG= 607215 Review-Url: https://codereview.chromium.org/2228283002 Cr-Commit-Position: refs/heads/master@{#410995} [modify] https://crrev.com/400793e57acc5f8b315a27caf44edc1a362d7afc/third_party/WebKit/Source/bindings/core/v8/GeneratedCodeHelper.cpp [modify] https://crrev.com/400793e57acc5f8b315a27caf44edc1a362d7afc/third_party/WebKit/Source/bindings/core/v8/GeneratedCodeHelper.h [modify] https://crrev.com/400793e57acc5f8b315a27caf44edc1a362d7afc/third_party/WebKit/Source/bindings/scripts/v8_types.py [modify] https://crrev.com/400793e57acc5f8b315a27caf44edc1a362d7afc/third_party/WebKit/Source/bindings/tests/results/core/V8TestObject.cpp
,
Aug 24 2016
Can we close this bug? Or are there other problematic code pieces?
,
Aug 25 2016
Still there are two usage of "a ? b : c" in CPP_VALUE_TO_V8_VALUE but these aren't problems. |
||||
►
Sign in to add a comment |
||||
Comment 1 by yukishiino@chromium.org
, Jul 14 2016