| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "bindings/core/v8/ScriptFunction.h" | 5 #include "bindings/core/v8/ScriptFunction.h" |
| 6 | 6 |
| 7 #include "bindings/core/v8/V8Binding.h" | 7 #include "bindings/core/v8/V8Binding.h" |
| 8 | 8 |
| 9 namespace blink { | 9 namespace blink { |
| 10 | 10 |
| 11 v8::Local<v8::Function> ScriptFunction::bindToV8Function() | 11 v8::Local<v8::Function> ScriptFunction::bindToV8Function() |
| 12 { | 12 { |
| 13 #if ENABLE(ASSERT) |
| 14 DCHECK(!m_bindToV8FunctionAlreadyCalled); |
| 15 m_bindToV8FunctionAlreadyCalled = true; |
| 16 #endif |
| 17 |
| 13 v8::Isolate* isolate = m_scriptState->isolate(); | 18 v8::Isolate* isolate = m_scriptState->isolate(); |
| 14 v8::Local<v8::External> wrapper = v8::External::New(isolate, this); | 19 v8::Local<v8::External> wrapper = v8::External::New(isolate, this); |
| 15 m_scriptState->world().registerDOMObjectHolder(isolate, this, wrapper); | 20 m_scriptState->world().registerDOMObjectHolder(isolate, this, wrapper); |
| 16 return createClosure(&ScriptFunction::callCallback, wrapper, isolate); | 21 return v8::Function::New(m_scriptState->context(), callCallback, wrapper, 0,
v8::ConstructorBehavior::kThrow).ToLocalChecked(); |
| 17 } | 22 } |
| 18 | 23 |
| 19 void ScriptFunction::callCallback(const v8::FunctionCallbackInfo<v8::Value>& arg
s) | 24 void ScriptFunction::callCallback(const v8::FunctionCallbackInfo<v8::Value>& arg
s) |
| 20 { | 25 { |
| 21 ASSERT(args.Data()->IsExternal()); | 26 ASSERT(args.Data()->IsExternal()); |
| 22 ScriptFunction* scriptFunction = static_cast<ScriptFunction*>(v8::Local<v8::
External>::Cast(args.Data())->Value()); | 27 ScriptFunction* scriptFunction = static_cast<ScriptFunction*>(v8::Local<v8::
External>::Cast(args.Data())->Value()); |
| 23 ScriptValue result = scriptFunction->call(ScriptValue(scriptFunction->getScr
iptState(), args[0])); | 28 ScriptValue result = scriptFunction->call(ScriptValue(scriptFunction->getScr
iptState(), args[0])); |
| 24 v8SetReturnValue(args, result.v8Value()); | 29 v8SetReturnValue(args, result.v8Value()); |
| 25 } | 30 } |
| 26 | 31 |
| 27 } // namespace blink | 32 } // namespace blink |
| OLD | NEW |