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