| 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 #if ENABLE(ASSERT) | 12 #if DCHECK_IS_ON() |
| 13 DCHECK(!m_bindToV8FunctionAlreadyCalled); | 13 DCHECK(!m_bindToV8FunctionAlreadyCalled); |
| 14 m_bindToV8FunctionAlreadyCalled = true; | 14 m_bindToV8FunctionAlreadyCalled = true; |
| 15 #endif | 15 #endif |
| 16 | 16 |
| 17 v8::Isolate* isolate = m_scriptState->isolate(); | 17 v8::Isolate* isolate = m_scriptState->isolate(); |
| 18 v8::Local<v8::External> wrapper = v8::External::New(isolate, this); | 18 v8::Local<v8::External> wrapper = v8::External::New(isolate, this); |
| 19 m_scriptState->world().registerDOMObjectHolder(isolate, this, wrapper); | 19 m_scriptState->world().registerDOMObjectHolder(isolate, this, wrapper); |
| 20 return v8::Function::New(m_scriptState->context(), callCallback, wrapper, 0, | 20 return v8::Function::New(m_scriptState->context(), callCallback, wrapper, 0, |
| 21 v8::ConstructorBehavior::kThrow) | 21 v8::ConstructorBehavior::kThrow) |
| 22 .ToLocalChecked(); | 22 .ToLocalChecked(); |
| 23 } | 23 } |
| 24 | 24 |
| 25 void ScriptFunction::callCallback( | 25 void ScriptFunction::callCallback( |
| 26 const v8::FunctionCallbackInfo<v8::Value>& args) { | 26 const v8::FunctionCallbackInfo<v8::Value>& args) { |
| 27 ASSERT(args.Data()->IsExternal()); | 27 ASSERT(args.Data()->IsExternal()); |
| 28 ScriptFunction* scriptFunction = static_cast<ScriptFunction*>( | 28 ScriptFunction* scriptFunction = static_cast<ScriptFunction*>( |
| 29 v8::Local<v8::External>::Cast(args.Data())->Value()); | 29 v8::Local<v8::External>::Cast(args.Data())->Value()); |
| 30 ScriptValue result = scriptFunction->call( | 30 ScriptValue result = scriptFunction->call( |
| 31 ScriptValue(scriptFunction->getScriptState(), args[0])); | 31 ScriptValue(scriptFunction->getScriptState(), args[0])); |
| 32 v8SetReturnValue(args, result.v8Value()); | 32 v8SetReturnValue(args, result.v8Value()); |
| 33 } | 33 } |
| 34 | 34 |
| 35 } // namespace blink | 35 } // namespace blink |
| OLD | NEW |