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

Side by Side Diff: src/builtins.cc

Issue 1683043003: Implement symbol @@hasInstance for ES6 instanceof support. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Fix broken test. Created 4 years, 10 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/builtins.h ('k') | src/heap-symbols.h » ('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/builtins.h" 5 #include "src/builtins.h"
6 6
7 #include "src/api.h" 7 #include "src/api.h"
8 #include "src/api-natives.h" 8 #include "src/api-natives.h"
9 #include "src/arguments.h" 9 #include "src/arguments.h"
10 #include "src/base/once.h" 10 #include "src/base/once.h"
(...skipping 3465 matching lines...) Expand 10 before | Expand all | Expand 10 after
3476 3476
3477 // ES6 section 25.2.1.1 GeneratorFunction (p1, p2, ... , pn, body) 3477 // ES6 section 25.2.1.1 GeneratorFunction (p1, p2, ... , pn, body)
3478 BUILTIN(GeneratorFunctionConstructor) { 3478 BUILTIN(GeneratorFunctionConstructor) {
3479 HandleScope scope(isolate); 3479 HandleScope scope(isolate);
3480 Handle<JSFunction> result; 3480 Handle<JSFunction> result;
3481 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( 3481 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
3482 isolate, result, CreateDynamicFunction(isolate, args, "function*")); 3482 isolate, result, CreateDynamicFunction(isolate, args, "function*"));
3483 return *result; 3483 return *result;
3484 } 3484 }
3485 3485
3486 // ES6 section 19.2.3.6 Function.prototype[@@hasInstance](V)
3487 BUILTIN(FunctionHasInstance) {
3488 HandleScope scope(isolate);
3489 Handle<Object> callable = args.receiver();
3490 Handle<Object> object = args.atOrUndefined(isolate, 1);
3491
3492 // {callable} must have a [[Call]] internal method.
3493 if (!callable->IsCallable()) {
3494 return isolate->heap()->false_value();
3495 }
3496 // If {object} is not a receiver, return false.
3497 if (!object->IsJSReceiver()) {
3498 return isolate->heap()->false_value();
3499 }
3500 // Check if {callable} is bound, if so, get [[BoundTargetFunction]] from it
3501 // and use that instead of {callable}.
3502 while (callable->IsJSBoundFunction()) {
3503 callable =
3504 handle(Handle<JSBoundFunction>::cast(callable)->bound_target_function(),
3505 isolate);
3506 }
3507 DCHECK(callable->IsCallable());
3508 // Get the "prototype" of {callable}; raise an error if it's not a receiver.
3509 Handle<Object> prototype;
3510 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
3511 isolate, prototype,
3512 Object::GetProperty(callable, isolate->factory()->prototype_string()));
3513 if (!prototype->IsJSReceiver()) {
3514 THROW_NEW_ERROR_RETURN_FAILURE(
3515 isolate,
3516 NewTypeError(MessageTemplate::kInstanceofNonobjectProto, prototype));
3517 }
3518 // Return whether or not {prototype} is in the prototype chain of {object}.
3519 Handle<JSReceiver> receiver = Handle<JSReceiver>::cast(object);
3520 Maybe<bool> result =
3521 JSReceiver::HasInPrototypeChain(isolate, receiver, prototype);
3522 MAYBE_RETURN(result, isolate->heap()->exception());
3523 return isolate->heap()->ToBoolean(result.FromJust());
3524 }
3486 3525
3487 // ES6 section 19.4.1.1 Symbol ( [ description ] ) for the [[Call]] case. 3526 // ES6 section 19.4.1.1 Symbol ( [ description ] ) for the [[Call]] case.
3488 BUILTIN(SymbolConstructor) { 3527 BUILTIN(SymbolConstructor) {
3489 HandleScope scope(isolate); 3528 HandleScope scope(isolate);
3490 Handle<Symbol> result = isolate->factory()->NewSymbol(); 3529 Handle<Symbol> result = isolate->factory()->NewSymbol();
3491 Handle<Object> description = args.atOrUndefined(isolate, 1); 3530 Handle<Object> description = args.atOrUndefined(isolate, 1);
3492 if (!description->IsUndefined()) { 3531 if (!description->IsUndefined()) {
3493 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, description, 3532 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, description,
3494 Object::ToString(isolate, description)); 3533 Object::ToString(isolate, description));
3495 result->set_name(*description); 3534 result->set_name(*description);
(...skipping 780 matching lines...) Expand 10 before | Expand all | Expand 10 after
4276 BUILTIN_LIST_C(DEFINE_BUILTIN_ACCESSOR_C) 4315 BUILTIN_LIST_C(DEFINE_BUILTIN_ACCESSOR_C)
4277 BUILTIN_LIST_A(DEFINE_BUILTIN_ACCESSOR_A) 4316 BUILTIN_LIST_A(DEFINE_BUILTIN_ACCESSOR_A)
4278 BUILTIN_LIST_H(DEFINE_BUILTIN_ACCESSOR_H) 4317 BUILTIN_LIST_H(DEFINE_BUILTIN_ACCESSOR_H)
4279 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A) 4318 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A)
4280 #undef DEFINE_BUILTIN_ACCESSOR_C 4319 #undef DEFINE_BUILTIN_ACCESSOR_C
4281 #undef DEFINE_BUILTIN_ACCESSOR_A 4320 #undef DEFINE_BUILTIN_ACCESSOR_A
4282 4321
4283 4322
4284 } // namespace internal 4323 } // namespace internal
4285 } // namespace v8 4324 } // namespace v8
OLDNEW
« no previous file with comments | « src/builtins.h ('k') | src/heap-symbols.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698