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

Side by Side Diff: src/runtime/runtime-object.cc

Issue 1304633002: Correctify instanceof and make it optimizable. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Add arm64 port. Created 5 years, 4 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
OLDNEW
1 // Copyright 2014 the V8 project authors. All rights reserved. 1 // Copyright 2014 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/runtime/runtime-utils.h" 5 #include "src/runtime/runtime-utils.h"
6 6
7 #include "src/arguments.h" 7 #include "src/arguments.h"
8 #include "src/bootstrapper.h" 8 #include "src/bootstrapper.h"
9 #include "src/debug/debug.h" 9 #include "src/debug/debug.h"
10 #include "src/messages.h" 10 #include "src/messages.h"
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 } 255 }
256 return *result; 256 return *result;
257 } 257 }
258 Handle<Object> result; 258 Handle<Object> result;
259 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( 259 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
260 isolate, result, JSObject::SetPrototype(obj, prototype, true)); 260 isolate, result, JSObject::SetPrototype(obj, prototype, true));
261 return *result; 261 return *result;
262 } 262 }
263 263
264 264
265 RUNTIME_FUNCTION(Runtime_IsInPrototypeChain) {
266 SealHandleScope shs(isolate);
267 DCHECK(args.length() == 2);
268 // See ECMA-262, section 15.3.5.3, page 88 (steps 5 - 8).
269 CONVERT_ARG_CHECKED(Object, O, 0);
270 CONVERT_ARG_CHECKED(Object, V, 1);
271 return isolate->heap()->ToBoolean(V->HasInPrototypeChain(isolate, O));
272 }
273
274
275 // Enumerator used as indices into the array returned from GetOwnProperty 265 // Enumerator used as indices into the array returned from GetOwnProperty
276 enum PropertyDescriptorIndices { 266 enum PropertyDescriptorIndices {
277 IS_ACCESSOR_INDEX, 267 IS_ACCESSOR_INDEX,
278 VALUE_INDEX, 268 VALUE_INDEX,
279 GETTER_INDEX, 269 GETTER_INDEX,
280 SETTER_INDEX, 270 SETTER_INDEX,
281 WRITABLE_INDEX, 271 WRITABLE_INDEX,
282 ENUMERABLE_INDEX, 272 ENUMERABLE_INDEX,
283 CONFIGURABLE_INDEX, 273 CONFIGURABLE_INDEX,
284 DESCRIPTOR_SIZE 274 DESCRIPTOR_SIZE
(...skipping 1178 matching lines...) Expand 10 before | Expand all | Expand 10 after
1463 1453
1464 RUNTIME_FUNCTION(Runtime_StrictEquals) { 1454 RUNTIME_FUNCTION(Runtime_StrictEquals) {
1465 SealHandleScope scope(isolate); 1455 SealHandleScope scope(isolate);
1466 DCHECK_EQ(2, args.length()); 1456 DCHECK_EQ(2, args.length());
1467 CONVERT_ARG_CHECKED(Object, x, 0); 1457 CONVERT_ARG_CHECKED(Object, x, 0);
1468 CONVERT_ARG_CHECKED(Object, y, 1); 1458 CONVERT_ARG_CHECKED(Object, y, 1);
1469 // TODO(bmeurer): Change this at some point to return true/false instead. 1459 // TODO(bmeurer): Change this at some point to return true/false instead.
1470 return Smi::FromInt(x->StrictEquals(y) ? EQUAL : NOT_EQUAL); 1460 return Smi::FromInt(x->StrictEquals(y) ? EQUAL : NOT_EQUAL);
1471 } 1461 }
1472 1462
1463
1464 RUNTIME_FUNCTION(Runtime_InstanceOf) {
1465 // ECMA-262, section 11.8.6, page 54.
1466 HandleScope shs(isolate);
1467 DCHECK_EQ(2, args.length());
1468 DCHECK(args.length() == 2);
1469 CONVERT_ARG_HANDLE_CHECKED(Object, object, 0);
1470 CONVERT_ARG_HANDLE_CHECKED(Object, callable, 1);
1471 // {callable} must have a [[Call]] internal method.
1472 if (!callable->IsCallable()) {
1473 THROW_NEW_ERROR_RETURN_FAILURE(
1474 isolate,
1475 NewTypeError(MessageTemplate::kInstanceofFunctionExpected, callable));
1476 }
1477 // If {object} is not a receiver, return false.
1478 if (!object->IsJSReceiver()) {
1479 return isolate->heap()->false_value();
1480 }
1481 // Check if {callable} is bound, if so, get [[BoundFunction]] from it and use
1482 // that instead of {callable}.
1483 if (callable->IsJSFunction()) {
1484 Handle<JSFunction> function = Handle<JSFunction>::cast(callable);
1485 if (function->shared()->bound()) {
1486 Handle<FixedArray> bindings(function->function_bindings(), isolate);
1487 callable =
1488 handle(bindings->get(JSFunction::kBoundFunctionIndex), isolate);
1489 }
1490 }
1491 DCHECK(callable->IsCallable());
1492 // Get the "prototype" of {callable}; raise an error if it's not a receiver.
1493 Handle<Object> prototype;
1494 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
1495 isolate, prototype,
1496 Object::GetProperty(callable, isolate->factory()->prototype_string()));
1497 if (!prototype->IsJSReceiver()) {
1498 THROW_NEW_ERROR_RETURN_FAILURE(
1499 isolate,
1500 NewTypeError(MessageTemplate::kInstanceofNonobjectProto, prototype));
1501 }
1502 // Return whether or not {prototype} is in the prototype chain of {object}.
1503 return isolate->heap()->ToBoolean(
1504 object->HasInPrototypeChain(isolate, *prototype));
1505 }
1506
1507
1508 RUNTIME_FUNCTION(Runtime_HasInPrototypeChain) {
1509 SealHandleScope scope(isolate);
1510 DCHECK_EQ(2, args.length());
1511 CONVERT_ARG_CHECKED(Object, object, 0);
1512 CONVERT_ARG_CHECKED(Object, prototype, 1);
1513 return isolate->heap()->ToBoolean(
1514 object->HasInPrototypeChain(isolate, prototype));
1515 }
1516
1473 } // namespace internal 1517 } // namespace internal
1474 } // namespace v8 1518 } // namespace v8
OLDNEW
« src/arm/code-stubs-arm.cc ('K') | « src/runtime/runtime.h ('k') | src/v8natives.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698