Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(574)

Side by Side Diff: src/api.cc

Issue 1552473002: Revert of [runtime] Introduce dedicated JSBoundFunction to represent bound functions. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@FunctionConstructor
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/accessors.cc ('k') | src/api-natives.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project 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 "src/api.h" 5 #include "src/api.h"
6 6
7 #include <string.h> // For memcpy, strlen. 7 #include <string.h> // For memcpy, strlen.
8 #ifdef V8_USE_ADDRESS_SANITIZER 8 #ifdef V8_USE_ADDRESS_SANITIZER
9 #include <sanitizer/asan_interface.h> 9 #include <sanitizer/asan_interface.h>
10 #endif // V8_USE_ADDRESS_SANITIZER 10 #endif // V8_USE_ADDRESS_SANITIZER
(...skipping 4394 matching lines...) Expand 10 before | Expand all | Expand 10 after
4405 void Function::SetName(v8::Local<v8::String> name) { 4405 void Function::SetName(v8::Local<v8::String> name) {
4406 auto self = Utils::OpenHandle(this); 4406 auto self = Utils::OpenHandle(this);
4407 if (!self->IsJSFunction()) return; 4407 if (!self->IsJSFunction()) return;
4408 auto func = i::Handle<i::JSFunction>::cast(self); 4408 auto func = i::Handle<i::JSFunction>::cast(self);
4409 func->shared()->set_name(*Utils::OpenHandle(*name)); 4409 func->shared()->set_name(*Utils::OpenHandle(*name));
4410 } 4410 }
4411 4411
4412 4412
4413 Local<Value> Function::GetName() const { 4413 Local<Value> Function::GetName() const {
4414 auto self = Utils::OpenHandle(this); 4414 auto self = Utils::OpenHandle(this);
4415 if (self->IsJSBoundFunction()) { 4415 if (!self->IsJSFunction()) {
4416 auto func = i::Handle<i::JSBoundFunction>::cast(self); 4416 return ToApiHandle<Primitive>(
4417 return Utils::ToLocal(handle(func->name(), func->GetIsolate())); 4417 self->GetIsolate()->factory()->undefined_value());
4418 } 4418 }
4419 if (self->IsJSFunction()) { 4419 auto func = i::Handle<i::JSFunction>::cast(self);
4420 auto func = i::Handle<i::JSFunction>::cast(self); 4420 return Utils::ToLocal(i::Handle<i::Object>(func->shared()->name(),
4421 return Utils::ToLocal(handle(func->shared()->name(), func->GetIsolate())); 4421 func->GetIsolate()));
4422 }
4423 return ToApiHandle<Primitive>(
4424 self->GetIsolate()->factory()->undefined_value());
4425 } 4422 }
4426 4423
4427 4424
4428 Local<Value> Function::GetInferredName() const { 4425 Local<Value> Function::GetInferredName() const {
4429 auto self = Utils::OpenHandle(this); 4426 auto self = Utils::OpenHandle(this);
4430 if (!self->IsJSFunction()) { 4427 if (!self->IsJSFunction()) {
4431 return ToApiHandle<Primitive>( 4428 return ToApiHandle<Primitive>(
4432 self->GetIsolate()->factory()->undefined_value()); 4429 self->GetIsolate()->factory()->undefined_value());
4433 } 4430 }
4434 auto func = i::Handle<i::JSFunction>::cast(self); 4431 auto func = i::Handle<i::JSFunction>::cast(self);
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
4533 if (!func->shared()->script()->IsScript()) { 4530 if (!func->shared()->script()->IsScript()) {
4534 return v8::UnboundScript::kNoScriptId; 4531 return v8::UnboundScript::kNoScriptId;
4535 } 4532 }
4536 i::Handle<i::Script> script(i::Script::cast(func->shared()->script())); 4533 i::Handle<i::Script> script(i::Script::cast(func->shared()->script()));
4537 return script->id(); 4534 return script->id();
4538 } 4535 }
4539 4536
4540 4537
4541 Local<v8::Value> Function::GetBoundFunction() const { 4538 Local<v8::Value> Function::GetBoundFunction() const {
4542 auto self = Utils::OpenHandle(this); 4539 auto self = Utils::OpenHandle(this);
4543 if (self->IsJSBoundFunction()) { 4540 if (!self->IsJSFunction()) {
4544 auto bound_function = i::Handle<i::JSBoundFunction>::cast(self); 4541 return v8::Undefined(reinterpret_cast<v8::Isolate*>(self->GetIsolate()));
4545 auto bound_target_function = i::handle(
4546 bound_function->bound_target_function(), bound_function->GetIsolate());
4547 return Utils::CallableToLocal(bound_target_function);
4548 } 4542 }
4549 return v8::Undefined(reinterpret_cast<v8::Isolate*>(self->GetIsolate())); 4543 auto func = i::Handle<i::JSFunction>::cast(self);
4544 if (!func->shared()->bound()) {
4545 return v8::Undefined(reinterpret_cast<v8::Isolate*>(func->GetIsolate()));
4546 }
4547 i::Handle<i::BindingsArray> bound_args = i::Handle<i::BindingsArray>(
4548 i::BindingsArray::cast(func->function_bindings()));
4549 i::Handle<i::Object> original(bound_args->bound_function(),
4550 func->GetIsolate());
4551 return Utils::CallableToLocal(i::Handle<i::JSFunction>::cast(original));
4550 } 4552 }
4551 4553
4552 4554
4553 int Name::GetIdentityHash() { 4555 int Name::GetIdentityHash() {
4554 auto self = Utils::OpenHandle(this); 4556 auto self = Utils::OpenHandle(this);
4555 return static_cast<int>(self->Hash()); 4557 return static_cast<int>(self->Hash());
4556 } 4558 }
4557 4559
4558 4560
4559 int String::Length() const { 4561 int String::Length() const {
(...skipping 3977 matching lines...) Expand 10 before | Expand all | Expand 10 after
8537 Address callback_address = 8539 Address callback_address =
8538 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); 8540 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback));
8539 VMState<EXTERNAL> state(isolate); 8541 VMState<EXTERNAL> state(isolate);
8540 ExternalCallbackScope call_scope(isolate, callback_address); 8542 ExternalCallbackScope call_scope(isolate, callback_address);
8541 callback(info); 8543 callback(info);
8542 } 8544 }
8543 8545
8544 8546
8545 } // namespace internal 8547 } // namespace internal
8546 } // namespace v8 8548 } // namespace v8
OLDNEW
« no previous file with comments | « src/accessors.cc ('k') | src/api-natives.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698