| 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 // static | 14 // static |
| 15 {{cpp_class}}* {{cpp_class}}::create(ScriptState* scriptState, v8::Local<v8::Val
ue> callback) { | 15 {{cpp_class}}* {{cpp_class}}::Create(ScriptState* scriptState, v8::Local<v8::Val
ue> callback) { |
| 16 if (isUndefinedOrNull(callback)) | 16 if (IsUndefinedOrNull(callback)) |
| 17 return nullptr; | 17 return nullptr; |
| 18 return new {{cpp_class}}(scriptState, v8::Local<v8::Function>::Cast(callback))
; | 18 return new {{cpp_class}}(scriptState, v8::Local<v8::Function>::Cast(callback))
; |
| 19 } | 19 } |
| 20 | 20 |
| 21 {{cpp_class}}::{{cpp_class}}(ScriptState* scriptState, v8::Local<v8::Function> c
allback) | 21 {{cpp_class}}::{{cpp_class}}(ScriptState* scriptState, v8::Local<v8::Function> c
allback) |
| 22 : m_scriptState(scriptState), | 22 : m_scriptState(scriptState), |
| 23 m_callback(scriptState->isolate(), this, callback) { | 23 m_callback(scriptState->GetIsolate(), this, callback) { |
| 24 DCHECK(!m_callback.isEmpty()); | 24 DCHECK(!m_callback.IsEmpty()); |
| 25 } | 25 } |
| 26 | 26 |
| 27 DEFINE_TRACE_WRAPPERS({{cpp_class}}) { | 27 DEFINE_TRACE_WRAPPERS({{cpp_class}}) { |
| 28 visitor->traceWrappers(m_callback.cast<v8::Value>()); | 28 visitor->TraceWrappers(m_callback.Cast<v8::Value>()); |
| 29 } | 29 } |
| 30 | 30 |
| 31 bool {{cpp_class}}::call({{argument_declarations | join(', ')}}) { | 31 bool {{cpp_class}}::call({{argument_declarations | join(', ')}}) { |
| 32 if (m_callback.isEmpty()) | 32 if (m_callback.IsEmpty()) |
| 33 return false; | 33 return false; |
| 34 | 34 |
| 35 if (!m_scriptState->contextIsValid()) | 35 if (!m_scriptState->ContextIsValid()) |
| 36 return false; | 36 return false; |
| 37 | 37 |
| 38 ExecutionContext* context = m_scriptState->getExecutionContext(); | 38 ExecutionContext* context = m_scriptState->GetExecutionContext(); |
| 39 DCHECK(context); | 39 DCHECK(context); |
| 40 if (context->isContextSuspended() || context->isContextDestroyed()) | 40 if (context->IsContextSuspended() || context->IsContextDestroyed()) |
| 41 return false; | 41 return false; |
| 42 | 42 |
| 43 // TODO(bashi): Make sure that using DummyExceptionStateForTesting is OK. | 43 // TODO(bashi): Make sure that using DummyExceptionStateForTesting is OK. |
| 44 // crbug.com/653769 | 44 // crbug.com/653769 |
| 45 DummyExceptionStateForTesting exceptionState; | 45 DummyExceptionStateForTesting exceptionState; |
| 46 ScriptState::Scope scope(m_scriptState.get()); | 46 ScriptState::Scope scope(m_scriptState.Get()); |
| 47 v8::Isolate* isolate = m_scriptState->isolate(); | 47 v8::Isolate* isolate = m_scriptState->GetIsolate(); |
| 48 | 48 |
| 49 v8::Local<v8::Value> thisValue = ToV8( | 49 v8::Local<v8::Value> thisValue = ToV8( |
| 50 scriptWrappable, | 50 scriptWrappable, |
| 51 m_scriptState->context()->Global(), | 51 m_scriptState->GetContext()->Global(), |
| 52 isolate); | 52 isolate); |
| 53 | 53 |
| 54 {% for argument in arguments %} | 54 {% for argument in arguments %} |
| 55 v8::Local<v8::Value> {{argument.argument_name}} = {{argument.cpp_value_to_v8_v
alue}}; | 55 v8::Local<v8::Value> {{argument.argument_name}} = {{argument.cpp_value_to_v8_v
alue}}; |
| 56 {% endfor %} | 56 {% endfor %} |
| 57 {% if arguments %} | 57 {% if arguments %} |
| 58 v8::Local<v8::Value> argv[] = { {{arguments | join(', ', 'argument_name')}} }; | 58 v8::Local<v8::Value> argv[] = { {{arguments | join(', ', 'argument_name')}} }; |
| 59 {% else %} | 59 {% else %} |
| 60 {# Empty array initializers are illegal, and don\'t compile in MSVC. #} | 60 {# Empty array initializers are illegal, and don\'t compile in MSVC. #} |
| 61 v8::Local<v8::Value> *argv = nullptr; | 61 v8::Local<v8::Value> *argv = nullptr; |
| 62 {% endif %} | 62 {% endif %} |
| 63 v8::TryCatch exceptionCatcher(isolate); | 63 v8::TryCatch exceptionCatcher(isolate); |
| 64 exceptionCatcher.SetVerbose(true); | 64 exceptionCatcher.SetVerbose(true); |
| 65 | 65 |
| 66 v8::Local<v8::Value> v8ReturnValue; | 66 v8::Local<v8::Value> v8ReturnValue; |
| 67 if (!V8ScriptRunner::callFunction(m_callback.newLocal(isolate), | 67 if (!V8ScriptRunner::CallFunction(m_callback.NewLocal(isolate), |
| 68 context, | 68 context, |
| 69 thisValue, | 69 thisValue, |
| 70 {{arguments | length}}, | 70 {{arguments | length}}, |
| 71 argv, | 71 argv, |
| 72 isolate).ToLocal(&v8ReturnValue)) { | 72 isolate).ToLocal(&v8ReturnValue)) { |
| 73 return false; | 73 return false; |
| 74 } | 74 } |
| 75 | 75 |
| 76 {% if return_value %} | 76 {% if return_value %} |
| 77 {{v8_value_to_local_cpp_value(return_value) | indent(2)}} | 77 {{v8_value_to_local_cpp_value(return_value) | indent(2)}} |
| 78 returnValue = cppValue; | 78 returnValue = cppValue; |
| 79 {% endif %} | 79 {% endif %} |
| 80 return true; | 80 return true; |
| 81 } | 81 } |
| 82 | 82 |
| 83 {{cpp_class}}* NativeValueTraits<{{cpp_class}}>::nativeValue(v8::Isolate* isolat
e, v8::Local<v8::Value> value, ExceptionState& exceptionState) { | 83 {{cpp_class}}* NativeValueTraits<{{cpp_class}}>::NativeValue(v8::Isolate* isolat
e, v8::Local<v8::Value> value, ExceptionState& exceptionState) { |
| 84 {{cpp_class}}* nativeValue = {{cpp_class}}::create(ScriptState::current(isolat
e), value); | 84 {{cpp_class}}* nativeValue = {{cpp_class}}::Create(ScriptState::Current(isolat
e), value); |
| 85 if (!nativeValue) | 85 if (!nativeValue) |
| 86 exceptionState.throwTypeError("Unable to convert value to {{callback_functio
n_name}}."); | 86 exceptionState.ThrowTypeError("Unable to convert value to {{callback_functio
n_name}}."); |
| 87 return nativeValue; | 87 return nativeValue; |
| 88 } | 88 } |
| 89 | 89 |
| 90 } // namespace blink | 90 } // namespace blink |
| 91 | 91 |
| 92 {% endfilter %}{# format_blink_cpp_source_code #} | 92 {% endfilter %}{# format_blink_cpp_source_code #} |
| OLD | NEW |