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

Side by Side Diff: src/objects.cc

Issue 1980483003: [es6] Reintroduce the instanceof operator in the backends. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Igors comments. Created 4 years, 7 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/objects.h ('k') | src/parsing/parser.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 2015 the V8 project authors. All rights reserved. 1 // Copyright 2015 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/objects.h" 5 #include "src/objects.h"
6 6
7 #include <cmath> 7 #include <cmath>
8 #include <iomanip> 8 #include <iomanip>
9 #include <sstream> 9 #include <sstream>
10 10
(...skipping 553 matching lines...) Expand 10 before | Expand all | Expand 10 after
564 MaybeHandle<Object> Object::BitwiseXor(Isolate* isolate, Handle<Object> lhs, 564 MaybeHandle<Object> Object::BitwiseXor(Isolate* isolate, Handle<Object> lhs,
565 Handle<Object> rhs) { 565 Handle<Object> rhs) {
566 if (!lhs->IsNumber() || !rhs->IsNumber()) { 566 if (!lhs->IsNumber() || !rhs->IsNumber()) {
567 ASSIGN_RETURN_ON_EXCEPTION(isolate, lhs, Object::ToNumber(lhs), Object); 567 ASSIGN_RETURN_ON_EXCEPTION(isolate, lhs, Object::ToNumber(lhs), Object);
568 ASSIGN_RETURN_ON_EXCEPTION(isolate, rhs, Object::ToNumber(rhs), Object); 568 ASSIGN_RETURN_ON_EXCEPTION(isolate, rhs, Object::ToNumber(rhs), Object);
569 } 569 }
570 return isolate->factory()->NewNumberFromInt(NumberToInt32(*lhs) ^ 570 return isolate->factory()->NewNumberFromInt(NumberToInt32(*lhs) ^
571 NumberToInt32(*rhs)); 571 NumberToInt32(*rhs));
572 } 572 }
573 573
574 // static
575 MaybeHandle<Object> Object::OrdinaryHasInstance(Isolate* isolate,
576 Handle<Object> callable,
577 Handle<Object> object) {
578 // The {callable} must have a [[Call]] internal method.
579 if (!callable->IsCallable()) return isolate->factory()->false_value();
580
581 // Check if {callable} is a bound function, and if so retrieve its
582 // [[BoundTargetFunction]] and use that instead of {callable}.
583 if (callable->IsJSBoundFunction()) {
584 Handle<Object> bound_callable(
585 Handle<JSBoundFunction>::cast(callable)->bound_target_function(),
586 isolate);
587 return Object::InstanceOf(isolate, object, bound_callable);
588 }
589
590 // If {object} is not a receiver, return false.
591 if (!object->IsJSReceiver()) return isolate->factory()->false_value();
592
593 // Get the "prototype" of {callable}; raise an error if it's not a receiver.
594 Handle<Object> prototype;
595 ASSIGN_RETURN_ON_EXCEPTION(
596 isolate, prototype,
597 Object::GetProperty(callable, isolate->factory()->prototype_string()),
598 Object);
599 if (!prototype->IsJSReceiver()) {
600 THROW_NEW_ERROR(
601 isolate,
602 NewTypeError(MessageTemplate::kInstanceofNonobjectProto, prototype),
603 Object);
604 }
605
606 // Return whether or not {prototype} is in the prototype chain of {object}.
607 Maybe<bool> result = JSReceiver::HasInPrototypeChain(
608 isolate, Handle<JSReceiver>::cast(object), prototype);
609 if (result.IsNothing()) return MaybeHandle<Object>();
610 return isolate->factory()->ToBoolean(result.FromJust());
611 }
612
613 // static
614 MaybeHandle<Object> Object::InstanceOf(Isolate* isolate, Handle<Object> object,
615 Handle<Object> callable) {
616 if (FLAG_harmony_instanceof) {
617 // The {callable} must be a receiver.
618 if (!callable->IsJSReceiver()) {
619 THROW_NEW_ERROR(
620 isolate, NewTypeError(MessageTemplate::kNonObjectInInstanceOfCheck),
621 Object);
622 }
623
624 // Lookup the @@hasInstance method on {callable}.
625 Handle<Object> inst_of_handler;
626 ASSIGN_RETURN_ON_EXCEPTION(
627 isolate, inst_of_handler,
628 JSReceiver::GetMethod(Handle<JSReceiver>::cast(callable),
629 isolate->factory()->has_instance_symbol()),
630 Object);
631 if (!inst_of_handler->IsUndefined()) {
632 // Call the {inst_of_handler} on the {callable}.
633 Handle<Object> result;
634 ASSIGN_RETURN_ON_EXCEPTION(
635 isolate, result,
636 Execution::Call(isolate, inst_of_handler, callable, 1, &object),
637 Object);
638 return isolate->factory()->ToBoolean(result->BooleanValue());
639 }
640 }
641
642 // The {callable} must have a [[Call]] internal method.
643 if (!callable->IsCallable()) {
644 THROW_NEW_ERROR(
645 isolate, NewTypeError(MessageTemplate::kNonCallableInInstanceOfCheck),
646 Object);
647 }
648
649 // Fall back to OrdinaryHasInstance with {callable} and {object}.
650 Handle<Object> result;
651 ASSIGN_RETURN_ON_EXCEPTION(
652 isolate, result,
653 JSReceiver::OrdinaryHasInstance(isolate, callable, object), Object);
654 return result;
655 }
574 656
575 Maybe<bool> Object::IsArray(Handle<Object> object) { 657 Maybe<bool> Object::IsArray(Handle<Object> object) {
576 if (object->IsJSArray()) return Just(true); 658 if (object->IsJSArray()) return Just(true);
577 if (object->IsJSProxy()) { 659 if (object->IsJSProxy()) {
578 Handle<JSProxy> proxy = Handle<JSProxy>::cast(object); 660 Handle<JSProxy> proxy = Handle<JSProxy>::cast(object);
579 Isolate* isolate = proxy->GetIsolate(); 661 Isolate* isolate = proxy->GetIsolate();
580 if (proxy->IsRevoked()) { 662 if (proxy->IsRevoked()) {
581 isolate->Throw(*isolate->factory()->NewTypeError( 663 isolate->Throw(*isolate->factory()->NewTypeError(
582 MessageTemplate::kProxyRevoked, 664 MessageTemplate::kProxyRevoked,
583 isolate->factory()->NewStringFromAsciiChecked("IsArray"))); 665 isolate->factory()->NewStringFromAsciiChecked("IsArray")));
(...skipping 798 matching lines...) Expand 10 before | Expand all | Expand 10 after
1382 } else { 1464 } else {
1383 PropertyDetails original_details = property_dictionary->DetailsAt(entry); 1465 PropertyDetails original_details = property_dictionary->DetailsAt(entry);
1384 int enumeration_index = original_details.dictionary_index(); 1466 int enumeration_index = original_details.dictionary_index();
1385 DCHECK(enumeration_index > 0); 1467 DCHECK(enumeration_index > 0);
1386 details = details.set_index(enumeration_index); 1468 details = details.set_index(enumeration_index);
1387 property_dictionary->SetEntry(entry, name, value, details); 1469 property_dictionary->SetEntry(entry, name, value, details);
1388 } 1470 }
1389 } 1471 }
1390 } 1472 }
1391 1473
1474 // static
1392 Maybe<bool> JSReceiver::HasInPrototypeChain(Isolate* isolate, 1475 Maybe<bool> JSReceiver::HasInPrototypeChain(Isolate* isolate,
1393 Handle<JSReceiver> object, 1476 Handle<JSReceiver> object,
1394 Handle<Object> proto) { 1477 Handle<Object> proto) {
1395 PrototypeIterator iter(isolate, object, PrototypeIterator::START_AT_RECEIVER); 1478 PrototypeIterator iter(isolate, object, PrototypeIterator::START_AT_RECEIVER);
1396 while (true) { 1479 while (true) {
1397 if (!iter.AdvanceFollowingProxies()) return Nothing<bool>(); 1480 if (!iter.AdvanceFollowingProxies()) return Nothing<bool>();
1398 if (iter.IsAtEnd()) return Just(false); 1481 if (iter.IsAtEnd()) return Just(false);
1399 if (PrototypeIterator::GetCurrent(iter).is_identical_to(proto)) { 1482 if (PrototypeIterator::GetCurrent(iter).is_identical_to(proto)) {
1400 return Just(true); 1483 return Just(true);
1401 } 1484 }
1402 } 1485 }
1403 } 1486 }
1404 1487
1405
1406 Map* Object::GetRootMap(Isolate* isolate) { 1488 Map* Object::GetRootMap(Isolate* isolate) {
1407 DisallowHeapAllocation no_alloc; 1489 DisallowHeapAllocation no_alloc;
1408 if (IsSmi()) { 1490 if (IsSmi()) {
1409 Context* native_context = isolate->context()->native_context(); 1491 Context* native_context = isolate->context()->native_context();
1410 return native_context->number_function()->initial_map(); 1492 return native_context->number_function()->initial_map();
1411 } 1493 }
1412 1494
1413 // The object is either a number, a string, a symbol, a boolean, a SIMD value, 1495 // The object is either a number, a string, a symbol, a boolean, a SIMD value,
1414 // a real JS object, or a Harmony proxy. 1496 // a real JS object, or a Harmony proxy.
1415 HeapObject* heap_object = HeapObject::cast(this); 1497 HeapObject* heap_object = HeapObject::cast(this);
(...skipping 16883 matching lines...) Expand 10 before | Expand all | Expand 10 after
18299 if (cell->value() != *new_value) { 18381 if (cell->value() != *new_value) {
18300 cell->set_value(*new_value); 18382 cell->set_value(*new_value);
18301 Isolate* isolate = cell->GetIsolate(); 18383 Isolate* isolate = cell->GetIsolate();
18302 cell->dependent_code()->DeoptimizeDependentCodeGroup( 18384 cell->dependent_code()->DeoptimizeDependentCodeGroup(
18303 isolate, DependentCode::kPropertyCellChangedGroup); 18385 isolate, DependentCode::kPropertyCellChangedGroup);
18304 } 18386 }
18305 } 18387 }
18306 18388
18307 } // namespace internal 18389 } // namespace internal
18308 } // namespace v8 18390 } // namespace v8
OLDNEW
« no previous file with comments | « src/objects.h ('k') | src/parsing/parser.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698