OLD | NEW |
1 {% filter format_blink_cpp_source_code %} | 1 {% filter format_blink_cpp_source_code %} |
2 | 2 |
3 {% include 'copyright_block.txt' %} | 3 {% include 'copyright_block.txt' %} |
4 #include "{{v8_class}}.h" | 4 #include "{{v8_class}}.h" |
5 | 5 |
6 {% for filename in cpp_includes %} | 6 {% for filename in cpp_includes %} |
7 #include "{{filename}}" | 7 #include "{{filename}}" |
8 {% endfor %} | 8 {% endfor %} |
9 | 9 |
10 namespace blink { | 10 namespace blink { |
11 | 11 |
12 {{v8_class}}::{{v8_class}}(v8::Local<v8::Function> callback, ScriptState* script
State) | 12 {{v8_class}}::{{v8_class}}(v8::Local<v8::Function> callback, ScriptState* script
State) |
13 : m_scriptState(scriptState) { | 13 : script_state_(scriptState) { |
14 m_callback.Set(scriptState->GetIsolate(), callback); | 14 m_callback.Set(scriptState->GetIsolate(), callback); |
15 } | 15 } |
16 | 16 |
17 {{v8_class}}::~{{v8_class}}() {} | 17 {{v8_class}}::~{{v8_class}}() {} |
18 | 18 |
19 DEFINE_TRACE({{v8_class}}) { | 19 DEFINE_TRACE({{v8_class}}) { |
20 {{cpp_class}}::Trace(visitor); | 20 {{cpp_class}}::Trace(visitor); |
21 } | 21 } |
22 | 22 |
23 {% for method in methods if not method.is_custom %} | 23 {% for method in methods if not method.is_custom %} |
24 {{method.cpp_type}} {{v8_class}}::{{method.name}}({{method.argument_declarations
| join(', ')}}) { | 24 {{method.cpp_type}} {{v8_class}}::{{method.name}}({{method.argument_declarations
| join(', ')}}) { |
25 {% set return_default = 'return true' | 25 {% set return_default = 'return true' |
26 if method.idl_type == 'boolean' else 'return' %}{# void #} | 26 if method.idl_type == 'boolean' else 'return' %}{# void #} |
27 ExecutionContext* executionContext = | 27 ExecutionContext* executionContext = |
28 ExecutionContext::From(m_scriptState.Get()); | 28 ExecutionContext::From(script_state_.Get()); |
29 DCHECK(!executionContext->IsContextSuspended()); | 29 DCHECK(!executionContext->IsContextSuspended()); |
30 if (!executionContext || executionContext->IsContextDestroyed()) | 30 if (!executionContext || executionContext->IsContextDestroyed()) |
31 {{return_default}}; | 31 {{return_default}}; |
32 if (!m_scriptState->ContextIsValid()) | 32 if (!script_state_->ContextIsValid()) |
33 {{return_default}}; | 33 {{return_default}}; |
34 | 34 |
35 ScriptState::Scope scope(m_scriptState.Get()); | 35 ScriptState::Scope scope(script_state_.Get()); |
36 {% if method.call_with_this_handle %} | 36 {% if method.call_with_this_handle %} |
37 v8::Local<v8::Value> thisHandle = thisValue.V8Value(); | 37 v8::Local<v8::Value> thisHandle = thisValue.V8Value(); |
38 {% endif %} | 38 {% endif %} |
39 | 39 |
40 {% for argument in method.arguments %} | 40 {% for argument in method.arguments %} |
41 v8::Local<v8::Value> {{argument.handle}} = {{argument.cpp_value_to_v8_value}}; | 41 v8::Local<v8::Value> {{argument.handle}} = {{argument.cpp_value_to_v8_value}}; |
42 {% endfor %} | 42 {% endfor %} |
43 {% if method.arguments %} | 43 {% if method.arguments %} |
44 v8::Local<v8::Value> argv[] = { {{method.arguments | join(', ', 'handle')}} }; | 44 v8::Local<v8::Value> argv[] = { {{method.arguments | join(', ', 'handle')}} }; |
45 {% else %} | 45 {% else %} |
46 {# Empty array initializers are illegal, and don\'t compile in MSVC. #} | 46 {# Empty array initializers are illegal, and don\'t compile in MSVC. #} |
47 v8::Local<v8::Value> *argv = 0; | 47 v8::Local<v8::Value> *argv = 0; |
48 {% endif %} | 48 {% endif %} |
49 | 49 |
50 v8::Isolate* isolate = m_scriptState->GetIsolate(); | 50 v8::Isolate* isolate = script_state_->GetIsolate(); |
51 {% set this_handle_parameter = 'thisHandle' | 51 {% set this_handle_parameter = 'thisHandle' |
52 if method.call_with_this_handle else 'v8::Undefined(isolate)' %} | 52 if method.call_with_this_handle else 'v8::Undefined(isolate)' %} |
53 {% if method.idl_type == 'boolean' %} | 53 {% if method.idl_type == 'boolean' %} |
54 v8::TryCatch exceptionCatcher(isolate); | 54 v8::TryCatch exceptionCatcher(isolate); |
55 exceptionCatcher.SetVerbose(true); | 55 exceptionCatcher.SetVerbose(true); |
56 V8ScriptRunner::CallFunction(m_callback.NewLocal(isolate), | 56 V8ScriptRunner::CallFunction(m_callback.NewLocal(isolate), |
57 executionContext, | 57 executionContext, |
58 {{this_handle_parameter}}, | 58 {{this_handle_parameter}}, |
59 {{method.arguments | length}}, | 59 {{method.arguments | length}}, |
60 argv, | 60 argv, |
61 isolate); | 61 isolate); |
62 return !exceptionCatcher.HasCaught(); | 62 return !exceptionCatcher.HasCaught(); |
63 {% else %}{# void #} | 63 {% else %}{# void #} |
64 V8ScriptRunner::CallFunction(m_callback.NewLocal(isolate), | 64 V8ScriptRunner::CallFunction(m_callback.NewLocal(isolate), |
65 ExecutionContext::From(m_scriptState.Get()), | 65 ExecutionContext::From(script_state_.Get()), |
66 {{this_handle_parameter}}, | 66 {{this_handle_parameter}}, |
67 {{method.arguments | length}}, | 67 {{method.arguments | length}}, |
68 argv, | 68 argv, |
69 isolate); | 69 isolate); |
70 {% endif %} | 70 {% endif %} |
71 } | 71 } |
72 | 72 |
73 {% endfor %} | 73 {% endfor %} |
74 } // namespace blink | 74 } // namespace blink |
75 | 75 |
76 {% endfilter %}{# format_blink_cpp_source_code #} | 76 {% endfilter %}{# format_blink_cpp_source_code #} |
OLD | NEW |