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 : script_state_(scriptState), | 22 : script_state_(scriptState), |
23 m_callback(scriptState->GetIsolate(), this, callback) { | 23 callback_(scriptState->GetIsolate(), this, callback) { |
24 DCHECK(!m_callback.IsEmpty()); | 24 DCHECK(!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(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 (callback_.IsEmpty()) |
33 return false; | 33 return false; |
34 | 34 |
35 if (!script_state_->ContextIsValid()) | 35 if (!script_state_->ContextIsValid()) |
36 return false; | 36 return false; |
37 | 37 |
38 ExecutionContext* context = ExecutionContext::From(script_state_.Get()); | 38 ExecutionContext* context = ExecutionContext::From(script_state_.Get()); |
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 |
(...skipping 14 matching lines...) Expand all Loading... |
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(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(ExceptionMessages::FailedToConvertJSValue( | 86 exceptionState.ThrowTypeError(ExceptionMessages::FailedToConvertJSValue( |
87 "{{callback_function_name}}")); | 87 "{{callback_function_name}}")); |
88 } | 88 } |
89 return nativeValue; | 89 return nativeValue; |
90 } | 90 } |
91 | 91 |
92 } // namespace blink | 92 } // namespace blink |
93 | 93 |
94 {% endfilter %}{# format_blink_cpp_source_code #} | 94 {% endfilter %}{# format_blink_cpp_source_code #} |
OLD | NEW |