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 DCHECK_IS_ON() | 12 #if DCHECK_IS_ON() |
13 DCHECK(!bind_to_v8_function_already_called_); | 13 DCHECK(!bind_to_v8_function_already_called_); |
14 bind_to_v8_function_already_called_ = true; | 14 bind_to_v8_function_already_called_ = true; |
15 #endif | 15 #endif |
16 | 16 |
17 v8::Isolate* isolate = script_state_->GetIsolate(); | 17 v8::Isolate* isolate = script_state_->GetIsolate(); |
18 v8::Local<v8::External> wrapper = v8::External::New(isolate, this); | 18 v8::Local<v8::External> wrapper = v8::External::New(isolate, this); |
19 script_state_->World().RegisterDOMObjectHolder(isolate, this, wrapper); | 19 script_state_->World().RegisterDOMObjectHolder(isolate, this, wrapper); |
20 return v8::Function::New(script_state_->GetContext(), CallCallback, wrapper, | 20 return v8::Function::New(script_state_->GetContext(), CallCallback, wrapper, |
21 0, v8::ConstructorBehavior::kThrow) | 21 0, 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 DCHECK(args.Data()->IsExternal()); |
28 ScriptFunction* script_function = static_cast<ScriptFunction*>( | 28 ScriptFunction* script_function = static_cast<ScriptFunction*>( |
29 v8::Local<v8::External>::Cast(args.Data())->Value()); | 29 v8::Local<v8::External>::Cast(args.Data())->Value()); |
30 ScriptValue result = script_function->Call( | 30 ScriptValue result = script_function->Call( |
31 ScriptValue(script_function->GetScriptState(), args[0])); | 31 ScriptValue(script_function->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 |