| OLD | NEW |
| 1 {% from 'utilities.cpp.tmpl' import v8_value_to_local_cpp_value %} | 1 {% from 'utilities.cpp.tmpl' import v8_value_to_local_cpp_value %} |
| 2 {% filter format_blink_cpp_source_code %} | 2 {% filter format_blink_cpp_source_code %} |
| 3 | 3 |
| 4 {% include 'copyright_block.txt' %} | 4 {% include 'copyright_block.txt' %} |
| 5 | 5 |
| 6 #include "{{cpp_class}}.h" | 6 #include "{{cpp_class}}.h" |
| 7 | 7 |
| 8 {% for filename in cpp_includes %} | 8 {% for filename in cpp_includes %} |
| 9 #include "{{filename}}" | 9 #include "{{filename}}" |
| 10 {% endfor %} | 10 {% endfor %} |
| 11 | 11 |
| 12 namespace blink { | 12 namespace blink { |
| 13 | 13 |
| 14 {{cpp_class}}::{{cpp_class}}(v8::Isolate* isolate, v8::Local<v8::Function> callb
ack) | 14 {{cpp_class}}::{{cpp_class}}(ScriptState* scriptState, v8::Local<v8::Function> c
allback) |
| 15 : m_callback(isolate, callback) | 15 : m_scriptState(scriptState), |
| 16 m_callback(scriptState->isolate(), callback) |
| 16 { | 17 { |
| 17 DCHECK(!m_callback.isEmpty()); | 18 DCHECK(!m_callback.isEmpty()); |
| 18 m_callback.setPhantom(); | 19 m_callback.setPhantom(); |
| 19 } | 20 } |
| 20 | 21 |
| 21 DEFINE_TRACE({{cpp_class}}) | 22 DEFINE_TRACE({{cpp_class}}) |
| 22 { | 23 { |
| 23 } | 24 } |
| 24 | 25 |
| 25 DEFINE_TRACE_WRAPPERS({{cpp_class}}) | 26 DEFINE_TRACE_WRAPPERS({{cpp_class}}) |
| 26 { | 27 { |
| 27 visitor->traceWrappers(&m_callback.cast<v8::Object>()); | 28 visitor->traceWrappers(&m_callback.cast<v8::Object>()); |
| 28 } | 29 } |
| 29 | 30 |
| 30 bool {{cpp_class}}::call({{argument_declarations | join(', ')}}) | 31 bool {{cpp_class}}::call({{argument_declarations | join(', ')}}) |
| 31 { | 32 { |
| 32 if (!scriptState->contextIsValid()) | 33 if (!m_scriptState->contextIsValid()) |
| 33 return false; | 34 return false; |
| 34 | 35 |
| 35 ExecutionContext* context = scriptState->getExecutionContext(); | 36 ExecutionContext* context = m_scriptState->getExecutionContext(); |
| 36 DCHECK(context); | 37 DCHECK(context); |
| 37 if (context->activeDOMObjectsAreSuspended() || context->activeDOMObjectsAreS
topped()) | 38 if (context->activeDOMObjectsAreSuspended() || context->activeDOMObjectsAreS
topped()) |
| 38 return false; | 39 return false; |
| 39 | 40 |
| 40 if (m_callback.isEmpty()) | 41 if (m_callback.isEmpty()) |
| 41 return false; | 42 return false; |
| 42 | 43 |
| 43 // TODO(bashi): Make sure that using TrackExceptionState is OK. | 44 // TODO(bashi): Make sure that using TrackExceptionState is OK. |
| 44 // crbug.com/653769 | 45 // crbug.com/653769 |
| 45 TrackExceptionState exceptionState; | 46 TrackExceptionState exceptionState; |
| 46 ScriptState::Scope scope(scriptState); | 47 ScriptState::Scope scope(m_scriptState.get()); |
| 47 | 48 |
| 48 {% for argument in arguments %} | 49 {% for argument in arguments %} |
| 49 v8::Local<v8::Value> {{argument.argument_name}} = {{argument.cpp_value_to_v8
_value}}; | 50 v8::Local<v8::Value> {{argument.argument_name}} = {{argument.cpp_value_to_v8
_value}}; |
| 50 {% endfor %} | 51 {% endfor %} |
| 51 | 52 |
| 52 v8::Local<v8::Value> thisValue = toV8(scriptWrappable, scriptState->context(
)->Global(), scriptState->isolate()); | 53 v8::Local<v8::Value> thisValue = toV8(scriptWrappable, m_scriptState->contex
t()->Global(), m_scriptState->isolate()); |
| 53 | 54 |
| 54 {% if arguments %} | 55 {% if arguments %} |
| 55 v8::Local<v8::Value> argv[] = { {{arguments | join(', ', 'argument_name')}}
}; | 56 v8::Local<v8::Value> argv[] = { {{arguments | join(', ', 'argument_name')}}
}; |
| 56 {% else %} | 57 {% else %} |
| 57 {# Empty array initializers are illegal, and don\'t compile in MSVC. #} | 58 {# Empty array initializers are illegal, and don\'t compile in MSVC. #} |
| 58 v8::Local<v8::Value> *argv = nullptr; | 59 v8::Local<v8::Value> *argv = nullptr; |
| 59 {% endif %} | 60 {% endif %} |
| 60 | 61 |
| 61 v8::Local<v8::Value> v8ReturnValue; | 62 v8::Local<v8::Value> v8ReturnValue; |
| 62 v8::TryCatch exceptionCatcher(scriptState->isolate()); | 63 v8::TryCatch exceptionCatcher(m_scriptState->isolate()); |
| 63 exceptionCatcher.SetVerbose(true); | 64 exceptionCatcher.SetVerbose(true); |
| 64 | 65 |
| 65 if (V8ScriptRunner::callFunction(m_callback.newLocal(scriptState->isolate())
, scriptState->getExecutionContext(), thisValue, {{arguments | length}}, argv, s
criptState->isolate()).ToLocal(&v8ReturnValue)) | 66 if (V8ScriptRunner::callFunction(m_callback.newLocal(m_scriptState->isolate(
)), m_scriptState->getExecutionContext(), thisValue, {{arguments | length}}, arg
v, m_scriptState->isolate()).ToLocal(&v8ReturnValue)) |
| 66 { | 67 { |
| 67 {% if return_value %} | 68 {% if return_value %} |
| 68 {{v8_value_to_local_cpp_value(return_value) | indent(8)}} | 69 {{v8_value_to_local_cpp_value(return_value) | indent(8)}} |
| 69 returnValue = cppValue; | 70 returnValue = cppValue; |
| 70 {% endif %} | 71 {% endif %} |
| 71 return true; | 72 return true; |
| 72 } | 73 } |
| 73 return false; | 74 return false; |
| 74 } | 75 } |
| 75 | 76 |
| 76 } // namespace blink | 77 } // namespace blink |
| 77 | 78 |
| 78 {% endfilter %}{# format_blink_cpp_source_code #} | 79 {% endfilter %}{# format_blink_cpp_source_code #} |
| OLD | NEW |