New issue
Advanced search Search tips

Issue 607215 link

Starred by 2 users

Issue metadata

Status: Fixed
Owner:
Closed: Aug 2016
Cc:
Components:
EstimatedDays: ----
NextAction: ----
OS: All
Pri: 3
Type: Bug



Sign in to add a comment

Bindings generator can evaluate value more than once

Project Member Reported by jbroman@chromium.org, Apr 27 2016

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.
 
Cc: yukishiino@chromium.org bashi@chromium.org

Comment 2 by peria@chromium.org, Aug 8 2016

Cc: peria@chromium.org

Comment 4 by peria@chromium.org, Aug 24 2016

Owner: bashi@chromium.org
Status: Started (was: Untriaged)
Can we close this bug?  Or are there other problematic code pieces?

Comment 5 by bashi@chromium.org, Aug 25 2016

Status: Fixed (was: Started)
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