OLD | NEW |
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 Loading... |
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 1176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1461 | 1451 |
1462 RUNTIME_FUNCTION(Runtime_StrictEquals) { | 1452 RUNTIME_FUNCTION(Runtime_StrictEquals) { |
1463 SealHandleScope scope(isolate); | 1453 SealHandleScope scope(isolate); |
1464 DCHECK_EQ(2, args.length()); | 1454 DCHECK_EQ(2, args.length()); |
1465 CONVERT_ARG_CHECKED(Object, x, 0); | 1455 CONVERT_ARG_CHECKED(Object, x, 0); |
1466 CONVERT_ARG_CHECKED(Object, y, 1); | 1456 CONVERT_ARG_CHECKED(Object, y, 1); |
1467 // TODO(bmeurer): Change this at some point to return true/false instead. | 1457 // TODO(bmeurer): Change this at some point to return true/false instead. |
1468 return Smi::FromInt(x->StrictEquals(y) ? EQUAL : NOT_EQUAL); | 1458 return Smi::FromInt(x->StrictEquals(y) ? EQUAL : NOT_EQUAL); |
1469 } | 1459 } |
1470 | 1460 |
| 1461 |
| 1462 RUNTIME_FUNCTION(Runtime_InstanceOf) { |
| 1463 // ECMA-262, section 11.8.6, page 54. |
| 1464 HandleScope shs(isolate); |
| 1465 DCHECK_EQ(2, args.length()); |
| 1466 DCHECK(args.length() == 2); |
| 1467 CONVERT_ARG_HANDLE_CHECKED(Object, object, 0); |
| 1468 CONVERT_ARG_HANDLE_CHECKED(Object, callable, 1); |
| 1469 // {callable} must have a [[Call]] internal method. |
| 1470 if (!callable->IsCallable()) { |
| 1471 THROW_NEW_ERROR_RETURN_FAILURE( |
| 1472 isolate, |
| 1473 NewTypeError(MessageTemplate::kInstanceofFunctionExpected, callable)); |
| 1474 } |
| 1475 // If {object} is not a receiver, return false. |
| 1476 if (!object->IsJSReceiver()) { |
| 1477 return isolate->heap()->false_value(); |
| 1478 } |
| 1479 // Check if {callable} is bound, if so, get [[BoundFunction]] from it and use |
| 1480 // that instead of {callable}. |
| 1481 if (callable->IsJSFunction()) { |
| 1482 Handle<JSFunction> function = Handle<JSFunction>::cast(callable); |
| 1483 if (function->shared()->bound()) { |
| 1484 Handle<FixedArray> bindings(function->function_bindings(), isolate); |
| 1485 callable = |
| 1486 handle(bindings->get(JSFunction::kBoundFunctionIndex), isolate); |
| 1487 } |
| 1488 } |
| 1489 DCHECK(callable->IsCallable()); |
| 1490 // Get the "prototype" of {callable}; raise an error if it's not a receiver. |
| 1491 Handle<Object> prototype; |
| 1492 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
| 1493 isolate, prototype, |
| 1494 Object::GetProperty(callable, isolate->factory()->prototype_string())); |
| 1495 if (!prototype->IsJSReceiver()) { |
| 1496 THROW_NEW_ERROR_RETURN_FAILURE( |
| 1497 isolate, |
| 1498 NewTypeError(MessageTemplate::kInstanceofNonobjectProto, prototype)); |
| 1499 } |
| 1500 // Return whether or not {prototype} is in the prototype chain of {object}. |
| 1501 return isolate->heap()->ToBoolean( |
| 1502 object->HasInPrototypeChain(isolate, *prototype)); |
| 1503 } |
| 1504 |
| 1505 |
| 1506 RUNTIME_FUNCTION(Runtime_HasInPrototypeChain) { |
| 1507 SealHandleScope scope(isolate); |
| 1508 DCHECK_EQ(2, args.length()); |
| 1509 CONVERT_ARG_CHECKED(Object, object, 0); |
| 1510 CONVERT_ARG_CHECKED(Object, prototype, 1); |
| 1511 return isolate->heap()->ToBoolean( |
| 1512 object->HasInPrototypeChain(isolate, prototype)); |
| 1513 } |
| 1514 |
1471 } // namespace internal | 1515 } // namespace internal |
1472 } // namespace v8 | 1516 } // namespace v8 |
OLD | NEW |