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

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

Issue 1306303003: [es6] Implement spec compliant ToPrimitive in the runtime. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Address Michis comments. Created 5 years, 3 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 1407 matching lines...) Expand 10 before | Expand all | Expand 10 after
1418 CONVERT_ARG_HANDLE_CHECKED(Object, object, 0); 1418 CONVERT_ARG_HANDLE_CHECKED(Object, object, 0);
1419 Handle<JSReceiver> receiver; 1419 Handle<JSReceiver> receiver;
1420 if (JSReceiver::ToObject(isolate, object).ToHandle(&receiver)) { 1420 if (JSReceiver::ToObject(isolate, object).ToHandle(&receiver)) {
1421 return *receiver; 1421 return *receiver;
1422 } 1422 }
1423 THROW_NEW_ERROR_RETURN_FAILURE( 1423 THROW_NEW_ERROR_RETURN_FAILURE(
1424 isolate, NewTypeError(MessageTemplate::kUndefinedOrNullToObject)); 1424 isolate, NewTypeError(MessageTemplate::kUndefinedOrNullToObject));
1425 } 1425 }
1426 1426
1427 1427
1428 RUNTIME_FUNCTION(Runtime_ToPrimitive) {
1429 HandleScope scope(isolate);
1430 DCHECK_EQ(1, args.length());
1431 CONVERT_ARG_HANDLE_CHECKED(Object, input, 0);
1432 Handle<Object> result;
1433 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, result,
1434 Object::ToPrimitive(input));
1435 return *result;
1436 }
1437
1438
1439 RUNTIME_FUNCTION(Runtime_ToPrimitive_Number) {
1440 HandleScope scope(isolate);
1441 DCHECK_EQ(1, args.length());
1442 CONVERT_ARG_HANDLE_CHECKED(Object, input, 0);
1443 Handle<Object> result;
1444 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
1445 isolate, result, Object::ToPrimitive(input, ToPrimitiveHint::kNumber));
1446 return *result;
1447 }
1448
1449
1450 RUNTIME_FUNCTION(Runtime_ToPrimitive_String) {
1451 HandleScope scope(isolate);
1452 DCHECK_EQ(1, args.length());
1453 CONVERT_ARG_HANDLE_CHECKED(Object, input, 0);
1454 Handle<Object> result;
1455 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
1456 isolate, result, Object::ToPrimitive(input, ToPrimitiveHint::kString));
1457 return *result;
1458 }
1459
1460
1461 RUNTIME_FUNCTION(Runtime_OrdinaryToPrimitive) {
1462 HandleScope scope(isolate);
1463 DCHECK_EQ(2, args.length());
1464 CONVERT_ARG_HANDLE_CHECKED(JSReceiver, receiver, 0);
1465 CONVERT_ARG_HANDLE_CHECKED(String, hint, 1);
1466 Handle<Object> result;
1467 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
1468 isolate, result, JSReceiver::OrdinaryToPrimitive(receiver, hint));
1469 return *result;
1470 }
1471
1472
1473 RUNTIME_FUNCTION(Runtime_ToNumber) {
1474 HandleScope scope(isolate);
1475 DCHECK_EQ(1, args.length());
1476 CONVERT_ARG_HANDLE_CHECKED(Object, input, 0);
1477 Handle<Object> result;
1478 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, result,
1479 Object::ToNumber(isolate, input));
1480 return *result;
1481 }
1482
1483
1428 RUNTIME_FUNCTION(Runtime_StrictEquals) { 1484 RUNTIME_FUNCTION(Runtime_StrictEquals) {
1429 SealHandleScope scope(isolate); 1485 SealHandleScope scope(isolate);
1430 DCHECK_EQ(2, args.length()); 1486 DCHECK_EQ(2, args.length());
1431 CONVERT_ARG_CHECKED(Object, x, 0); 1487 CONVERT_ARG_CHECKED(Object, x, 0);
1432 CONVERT_ARG_CHECKED(Object, y, 1); 1488 CONVERT_ARG_CHECKED(Object, y, 1);
1433 // TODO(bmeurer): Change this at some point to return true/false instead. 1489 // TODO(bmeurer): Change this at some point to return true/false instead.
1434 return Smi::FromInt(x->StrictEquals(y) ? EQUAL : NOT_EQUAL); 1490 return Smi::FromInt(x->StrictEquals(y) ? EQUAL : NOT_EQUAL);
1435 } 1491 }
1436 1492
1437 1493
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
1483 SealHandleScope scope(isolate); 1539 SealHandleScope scope(isolate);
1484 DCHECK_EQ(2, args.length()); 1540 DCHECK_EQ(2, args.length());
1485 CONVERT_ARG_CHECKED(Object, object, 0); 1541 CONVERT_ARG_CHECKED(Object, object, 0);
1486 CONVERT_ARG_CHECKED(Object, prototype, 1); 1542 CONVERT_ARG_CHECKED(Object, prototype, 1);
1487 return isolate->heap()->ToBoolean( 1543 return isolate->heap()->ToBoolean(
1488 object->HasInPrototypeChain(isolate, prototype)); 1544 object->HasInPrototypeChain(isolate, prototype));
1489 } 1545 }
1490 1546
1491 } // namespace internal 1547 } // namespace internal
1492 } // namespace v8 1548 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698