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

Side by Side Diff: src/objects.cc

Issue 1693833002: Remove strong mode support from binary operations. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Addressed comments. 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
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 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 255
256 256
257 bool NumberEquals(Handle<Object> x, Handle<Object> y) { 257 bool NumberEquals(Handle<Object> x, Handle<Object> y) {
258 return NumberEquals(*x, *y); 258 return NumberEquals(*x, *y);
259 } 259 }
260 260
261 } // namespace 261 } // namespace
262 262
263 263
264 // static 264 // static
265 Maybe<ComparisonResult> Object::Compare(Handle<Object> x, Handle<Object> y, 265 Maybe<ComparisonResult> Object::Compare(Handle<Object> x, Handle<Object> y) {
266 Strength strength) { 266 // ES6 section 7.2.11 Abstract Relational Comparison step 3 and 4.
267 if (!is_strong(strength)) { 267 if (!Object::ToPrimitive(x, ToPrimitiveHint::kNumber).ToHandle(&x) ||
268 // ES6 section 7.2.11 Abstract Relational Comparison step 3 and 4. 268 !Object::ToPrimitive(y, ToPrimitiveHint::kNumber).ToHandle(&y)) {
269 if (!Object::ToPrimitive(x, ToPrimitiveHint::kNumber).ToHandle(&x) || 269 return Nothing<ComparisonResult>();
270 !Object::ToPrimitive(y, ToPrimitiveHint::kNumber).ToHandle(&y)) {
271 return Nothing<ComparisonResult>();
272 }
273 } 270 }
274 if (x->IsString() && y->IsString()) { 271 if (x->IsString() && y->IsString()) {
275 // ES6 section 7.2.11 Abstract Relational Comparison step 5. 272 // ES6 section 7.2.11 Abstract Relational Comparison step 5.
276 return Just( 273 return Just(
277 String::Compare(Handle<String>::cast(x), Handle<String>::cast(y))); 274 String::Compare(Handle<String>::cast(x), Handle<String>::cast(y)));
278 } 275 }
279 // ES6 section 7.2.11 Abstract Relational Comparison step 6. 276 // ES6 section 7.2.11 Abstract Relational Comparison step 6.
280 if (!is_strong(strength)) { 277 if (!Object::ToNumber(x).ToHandle(&x) || !Object::ToNumber(y).ToHandle(&y)) {
281 if (!Object::ToNumber(x).ToHandle(&x) || 278 return Nothing<ComparisonResult>();
282 !Object::ToNumber(y).ToHandle(&y)) {
283 return Nothing<ComparisonResult>();
284 }
285 } else {
286 if (!x->IsNumber()) {
287 Isolate* const isolate = Handle<HeapObject>::cast(x)->GetIsolate();
288 isolate->Throw(*isolate->factory()->NewTypeError(
289 MessageTemplate::kStrongImplicitConversion));
290 return Nothing<ComparisonResult>();
291 } else if (!y->IsNumber()) {
292 Isolate* const isolate = Handle<HeapObject>::cast(y)->GetIsolate();
293 isolate->Throw(*isolate->factory()->NewTypeError(
294 MessageTemplate::kStrongImplicitConversion));
295 return Nothing<ComparisonResult>();
296 }
297 } 279 }
298 return Just(NumberCompare(x->Number(), y->Number())); 280 return Just(NumberCompare(x->Number(), y->Number()));
299 } 281 }
300 282
301 283
302 // static 284 // static
303 Maybe<bool> Object::Equals(Handle<Object> x, Handle<Object> y) { 285 Maybe<bool> Object::Equals(Handle<Object> x, Handle<Object> y) {
304 while (true) { 286 while (true) {
305 if (x->IsNumber()) { 287 if (x->IsNumber()) {
306 if (y->IsNumber()) { 288 if (y->IsNumber()) {
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
424 if (object->Is##Type()) return isolate->factory()->type##_string(); 406 if (object->Is##Type()) return isolate->factory()->type##_string();
425 SIMD128_TYPES(SIMD128_TYPE) 407 SIMD128_TYPES(SIMD128_TYPE)
426 #undef SIMD128_TYPE 408 #undef SIMD128_TYPE
427 if (object->IsCallable()) return isolate->factory()->function_string(); 409 if (object->IsCallable()) return isolate->factory()->function_string();
428 return isolate->factory()->object_string(); 410 return isolate->factory()->object_string();
429 } 411 }
430 412
431 413
432 // static 414 // static
433 MaybeHandle<Object> Object::Multiply(Isolate* isolate, Handle<Object> lhs, 415 MaybeHandle<Object> Object::Multiply(Isolate* isolate, Handle<Object> lhs,
434 Handle<Object> rhs, Strength strength) { 416 Handle<Object> rhs) {
435 if (!lhs->IsNumber() || !rhs->IsNumber()) { 417 if (!lhs->IsNumber() || !rhs->IsNumber()) {
436 if (is_strong(strength)) {
437 THROW_NEW_ERROR(isolate,
438 NewTypeError(MessageTemplate::kStrongImplicitConversion),
439 Object);
440 }
441 ASSIGN_RETURN_ON_EXCEPTION(isolate, lhs, Object::ToNumber(lhs), Object); 418 ASSIGN_RETURN_ON_EXCEPTION(isolate, lhs, Object::ToNumber(lhs), Object);
442 ASSIGN_RETURN_ON_EXCEPTION(isolate, rhs, Object::ToNumber(rhs), Object); 419 ASSIGN_RETURN_ON_EXCEPTION(isolate, rhs, Object::ToNumber(rhs), Object);
443 } 420 }
444 return isolate->factory()->NewNumber(lhs->Number() * rhs->Number()); 421 return isolate->factory()->NewNumber(lhs->Number() * rhs->Number());
445 } 422 }
446 423
447 424
448 // static 425 // static
449 MaybeHandle<Object> Object::Divide(Isolate* isolate, Handle<Object> lhs, 426 MaybeHandle<Object> Object::Divide(Isolate* isolate, Handle<Object> lhs,
450 Handle<Object> rhs, Strength strength) { 427 Handle<Object> rhs) {
451 if (!lhs->IsNumber() || !rhs->IsNumber()) { 428 if (!lhs->IsNumber() || !rhs->IsNumber()) {
452 if (is_strong(strength)) {
453 THROW_NEW_ERROR(isolate,
454 NewTypeError(MessageTemplate::kStrongImplicitConversion),
455 Object);
456 }
457 ASSIGN_RETURN_ON_EXCEPTION(isolate, lhs, Object::ToNumber(lhs), Object); 429 ASSIGN_RETURN_ON_EXCEPTION(isolate, lhs, Object::ToNumber(lhs), Object);
458 ASSIGN_RETURN_ON_EXCEPTION(isolate, rhs, Object::ToNumber(rhs), Object); 430 ASSIGN_RETURN_ON_EXCEPTION(isolate, rhs, Object::ToNumber(rhs), Object);
459 } 431 }
460 return isolate->factory()->NewNumber(lhs->Number() / rhs->Number()); 432 return isolate->factory()->NewNumber(lhs->Number() / rhs->Number());
461 } 433 }
462 434
463 435
464 // static 436 // static
465 MaybeHandle<Object> Object::Modulus(Isolate* isolate, Handle<Object> lhs, 437 MaybeHandle<Object> Object::Modulus(Isolate* isolate, Handle<Object> lhs,
466 Handle<Object> rhs, Strength strength) { 438 Handle<Object> rhs) {
467 if (!lhs->IsNumber() || !rhs->IsNumber()) { 439 if (!lhs->IsNumber() || !rhs->IsNumber()) {
468 if (is_strong(strength)) {
469 THROW_NEW_ERROR(isolate,
470 NewTypeError(MessageTemplate::kStrongImplicitConversion),
471 Object);
472 }
473 ASSIGN_RETURN_ON_EXCEPTION(isolate, lhs, Object::ToNumber(lhs), Object); 440 ASSIGN_RETURN_ON_EXCEPTION(isolate, lhs, Object::ToNumber(lhs), Object);
474 ASSIGN_RETURN_ON_EXCEPTION(isolate, rhs, Object::ToNumber(rhs), Object); 441 ASSIGN_RETURN_ON_EXCEPTION(isolate, rhs, Object::ToNumber(rhs), Object);
475 } 442 }
476 return isolate->factory()->NewNumber(modulo(lhs->Number(), rhs->Number())); 443 return isolate->factory()->NewNumber(modulo(lhs->Number(), rhs->Number()));
477 } 444 }
478 445
479 446
480 // static 447 // static
481 MaybeHandle<Object> Object::Add(Isolate* isolate, Handle<Object> lhs, 448 MaybeHandle<Object> Object::Add(Isolate* isolate, Handle<Object> lhs,
482 Handle<Object> rhs, Strength strength) { 449 Handle<Object> rhs) {
483 if (lhs->IsNumber() && rhs->IsNumber()) { 450 if (lhs->IsNumber() && rhs->IsNumber()) {
484 return isolate->factory()->NewNumber(lhs->Number() + rhs->Number()); 451 return isolate->factory()->NewNumber(lhs->Number() + rhs->Number());
485 } else if (lhs->IsString() && rhs->IsString()) { 452 } else if (lhs->IsString() && rhs->IsString()) {
486 return isolate->factory()->NewConsString(Handle<String>::cast(lhs), 453 return isolate->factory()->NewConsString(Handle<String>::cast(lhs),
487 Handle<String>::cast(rhs)); 454 Handle<String>::cast(rhs));
488 } else if (is_strong(strength)) {
489 THROW_NEW_ERROR(isolate,
490 NewTypeError(MessageTemplate::kStrongImplicitConversion),
491 Object);
492 } 455 }
493 ASSIGN_RETURN_ON_EXCEPTION(isolate, lhs, Object::ToPrimitive(lhs), Object); 456 ASSIGN_RETURN_ON_EXCEPTION(isolate, lhs, Object::ToPrimitive(lhs), Object);
494 ASSIGN_RETURN_ON_EXCEPTION(isolate, rhs, Object::ToPrimitive(rhs), Object); 457 ASSIGN_RETURN_ON_EXCEPTION(isolate, rhs, Object::ToPrimitive(rhs), Object);
495 if (lhs->IsString() || rhs->IsString()) { 458 if (lhs->IsString() || rhs->IsString()) {
496 ASSIGN_RETURN_ON_EXCEPTION(isolate, rhs, Object::ToString(isolate, rhs), 459 ASSIGN_RETURN_ON_EXCEPTION(isolate, rhs, Object::ToString(isolate, rhs),
497 Object); 460 Object);
498 ASSIGN_RETURN_ON_EXCEPTION(isolate, lhs, Object::ToString(isolate, lhs), 461 ASSIGN_RETURN_ON_EXCEPTION(isolate, lhs, Object::ToString(isolate, lhs),
499 Object); 462 Object);
500 return isolate->factory()->NewConsString(Handle<String>::cast(lhs), 463 return isolate->factory()->NewConsString(Handle<String>::cast(lhs),
501 Handle<String>::cast(rhs)); 464 Handle<String>::cast(rhs));
502 } 465 }
503 ASSIGN_RETURN_ON_EXCEPTION(isolate, rhs, Object::ToNumber(rhs), Object); 466 ASSIGN_RETURN_ON_EXCEPTION(isolate, rhs, Object::ToNumber(rhs), Object);
504 ASSIGN_RETURN_ON_EXCEPTION(isolate, lhs, Object::ToNumber(lhs), Object); 467 ASSIGN_RETURN_ON_EXCEPTION(isolate, lhs, Object::ToNumber(lhs), Object);
505 return isolate->factory()->NewNumber(lhs->Number() + rhs->Number()); 468 return isolate->factory()->NewNumber(lhs->Number() + rhs->Number());
506 } 469 }
507 470
508 471
509 // static 472 // static
510 MaybeHandle<Object> Object::Subtract(Isolate* isolate, Handle<Object> lhs, 473 MaybeHandle<Object> Object::Subtract(Isolate* isolate, Handle<Object> lhs,
511 Handle<Object> rhs, Strength strength) { 474 Handle<Object> rhs) {
512 if (!lhs->IsNumber() || !rhs->IsNumber()) { 475 if (!lhs->IsNumber() || !rhs->IsNumber()) {
513 if (is_strong(strength)) {
514 THROW_NEW_ERROR(isolate,
515 NewTypeError(MessageTemplate::kStrongImplicitConversion),
516 Object);
517 }
518 ASSIGN_RETURN_ON_EXCEPTION(isolate, lhs, Object::ToNumber(lhs), Object); 476 ASSIGN_RETURN_ON_EXCEPTION(isolate, lhs, Object::ToNumber(lhs), Object);
519 ASSIGN_RETURN_ON_EXCEPTION(isolate, rhs, Object::ToNumber(rhs), Object); 477 ASSIGN_RETURN_ON_EXCEPTION(isolate, rhs, Object::ToNumber(rhs), Object);
520 } 478 }
521 return isolate->factory()->NewNumber(lhs->Number() - rhs->Number()); 479 return isolate->factory()->NewNumber(lhs->Number() - rhs->Number());
522 } 480 }
523 481
524 482
525 // static 483 // static
526 MaybeHandle<Object> Object::ShiftLeft(Isolate* isolate, Handle<Object> lhs, 484 MaybeHandle<Object> Object::ShiftLeft(Isolate* isolate, Handle<Object> lhs,
527 Handle<Object> rhs, Strength strength) { 485 Handle<Object> rhs) {
528 if (!lhs->IsNumber() || !rhs->IsNumber()) { 486 if (!lhs->IsNumber() || !rhs->IsNumber()) {
529 if (is_strong(strength)) {
530 THROW_NEW_ERROR(isolate,
531 NewTypeError(MessageTemplate::kStrongImplicitConversion),
532 Object);
533 }
534 ASSIGN_RETURN_ON_EXCEPTION(isolate, lhs, Object::ToNumber(lhs), Object); 487 ASSIGN_RETURN_ON_EXCEPTION(isolate, lhs, Object::ToNumber(lhs), Object);
535 ASSIGN_RETURN_ON_EXCEPTION(isolate, rhs, Object::ToNumber(rhs), Object); 488 ASSIGN_RETURN_ON_EXCEPTION(isolate, rhs, Object::ToNumber(rhs), Object);
536 } 489 }
537 return isolate->factory()->NewNumberFromInt(NumberToInt32(*lhs) 490 return isolate->factory()->NewNumberFromInt(NumberToInt32(*lhs)
538 << (NumberToUint32(*rhs) & 0x1F)); 491 << (NumberToUint32(*rhs) & 0x1F));
539 } 492 }
540 493
541 494
542 // static 495 // static
543 MaybeHandle<Object> Object::ShiftRight(Isolate* isolate, Handle<Object> lhs, 496 MaybeHandle<Object> Object::ShiftRight(Isolate* isolate, Handle<Object> lhs,
544 Handle<Object> rhs, Strength strength) { 497 Handle<Object> rhs) {
545 if (!lhs->IsNumber() || !rhs->IsNumber()) { 498 if (!lhs->IsNumber() || !rhs->IsNumber()) {
546 if (is_strong(strength)) {
547 THROW_NEW_ERROR(isolate,
548 NewTypeError(MessageTemplate::kStrongImplicitConversion),
549 Object);
550 }
551 ASSIGN_RETURN_ON_EXCEPTION(isolate, lhs, Object::ToNumber(lhs), Object); 499 ASSIGN_RETURN_ON_EXCEPTION(isolate, lhs, Object::ToNumber(lhs), Object);
552 ASSIGN_RETURN_ON_EXCEPTION(isolate, rhs, Object::ToNumber(rhs), Object); 500 ASSIGN_RETURN_ON_EXCEPTION(isolate, rhs, Object::ToNumber(rhs), Object);
553 } 501 }
554 return isolate->factory()->NewNumberFromInt(NumberToInt32(*lhs) >> 502 return isolate->factory()->NewNumberFromInt(NumberToInt32(*lhs) >>
555 (NumberToUint32(*rhs) & 0x1F)); 503 (NumberToUint32(*rhs) & 0x1F));
556 } 504 }
557 505
558 506
559 // static 507 // static
560 MaybeHandle<Object> Object::ShiftRightLogical(Isolate* isolate, 508 MaybeHandle<Object> Object::ShiftRightLogical(Isolate* isolate,
561 Handle<Object> lhs, 509 Handle<Object> lhs,
562 Handle<Object> rhs, 510 Handle<Object> rhs) {
563 Strength strength) {
564 if (!lhs->IsNumber() || !rhs->IsNumber()) { 511 if (!lhs->IsNumber() || !rhs->IsNumber()) {
565 if (is_strong(strength)) {
566 THROW_NEW_ERROR(isolate,
567 NewTypeError(MessageTemplate::kStrongImplicitConversion),
568 Object);
569 }
570 ASSIGN_RETURN_ON_EXCEPTION(isolate, lhs, Object::ToNumber(lhs), Object); 512 ASSIGN_RETURN_ON_EXCEPTION(isolate, lhs, Object::ToNumber(lhs), Object);
571 ASSIGN_RETURN_ON_EXCEPTION(isolate, rhs, Object::ToNumber(rhs), Object); 513 ASSIGN_RETURN_ON_EXCEPTION(isolate, rhs, Object::ToNumber(rhs), Object);
572 } 514 }
573 return isolate->factory()->NewNumberFromUint(NumberToUint32(*lhs) >> 515 return isolate->factory()->NewNumberFromUint(NumberToUint32(*lhs) >>
574 (NumberToUint32(*rhs) & 0x1F)); 516 (NumberToUint32(*rhs) & 0x1F));
575 } 517 }
576 518
577 519
578 // static 520 // static
579 MaybeHandle<Object> Object::BitwiseAnd(Isolate* isolate, Handle<Object> lhs, 521 MaybeHandle<Object> Object::BitwiseAnd(Isolate* isolate, Handle<Object> lhs,
580 Handle<Object> rhs, Strength strength) { 522 Handle<Object> rhs) {
581 if (!lhs->IsNumber() || !rhs->IsNumber()) { 523 if (!lhs->IsNumber() || !rhs->IsNumber()) {
582 if (is_strong(strength)) {
583 THROW_NEW_ERROR(isolate,
584 NewTypeError(MessageTemplate::kStrongImplicitConversion),
585 Object);
586 }
587 ASSIGN_RETURN_ON_EXCEPTION(isolate, lhs, Object::ToNumber(lhs), Object); 524 ASSIGN_RETURN_ON_EXCEPTION(isolate, lhs, Object::ToNumber(lhs), Object);
588 ASSIGN_RETURN_ON_EXCEPTION(isolate, rhs, Object::ToNumber(rhs), Object); 525 ASSIGN_RETURN_ON_EXCEPTION(isolate, rhs, Object::ToNumber(rhs), Object);
589 } 526 }
590 return isolate->factory()->NewNumberFromInt(NumberToInt32(*lhs) & 527 return isolate->factory()->NewNumberFromInt(NumberToInt32(*lhs) &
591 NumberToInt32(*rhs)); 528 NumberToInt32(*rhs));
592 } 529 }
593 530
594 531
595 // static 532 // static
596 MaybeHandle<Object> Object::BitwiseOr(Isolate* isolate, Handle<Object> lhs, 533 MaybeHandle<Object> Object::BitwiseOr(Isolate* isolate, Handle<Object> lhs,
597 Handle<Object> rhs, Strength strength) { 534 Handle<Object> rhs) {
598 if (!lhs->IsNumber() || !rhs->IsNumber()) { 535 if (!lhs->IsNumber() || !rhs->IsNumber()) {
599 if (is_strong(strength)) {
600 THROW_NEW_ERROR(isolate,
601 NewTypeError(MessageTemplate::kStrongImplicitConversion),
602 Object);
603 }
604 ASSIGN_RETURN_ON_EXCEPTION(isolate, lhs, Object::ToNumber(lhs), Object); 536 ASSIGN_RETURN_ON_EXCEPTION(isolate, lhs, Object::ToNumber(lhs), Object);
605 ASSIGN_RETURN_ON_EXCEPTION(isolate, rhs, Object::ToNumber(rhs), Object); 537 ASSIGN_RETURN_ON_EXCEPTION(isolate, rhs, Object::ToNumber(rhs), Object);
606 } 538 }
607 return isolate->factory()->NewNumberFromInt(NumberToInt32(*lhs) | 539 return isolate->factory()->NewNumberFromInt(NumberToInt32(*lhs) |
608 NumberToInt32(*rhs)); 540 NumberToInt32(*rhs));
609 } 541 }
610 542
611 543
612 // static 544 // static
613 MaybeHandle<Object> Object::BitwiseXor(Isolate* isolate, Handle<Object> lhs, 545 MaybeHandle<Object> Object::BitwiseXor(Isolate* isolate, Handle<Object> lhs,
614 Handle<Object> rhs, Strength strength) { 546 Handle<Object> rhs) {
615 if (!lhs->IsNumber() || !rhs->IsNumber()) { 547 if (!lhs->IsNumber() || !rhs->IsNumber()) {
616 if (is_strong(strength)) {
617 THROW_NEW_ERROR(isolate,
618 NewTypeError(MessageTemplate::kStrongImplicitConversion),
619 Object);
620 }
621 ASSIGN_RETURN_ON_EXCEPTION(isolate, lhs, Object::ToNumber(lhs), Object); 548 ASSIGN_RETURN_ON_EXCEPTION(isolate, lhs, Object::ToNumber(lhs), Object);
622 ASSIGN_RETURN_ON_EXCEPTION(isolate, rhs, Object::ToNumber(rhs), Object); 549 ASSIGN_RETURN_ON_EXCEPTION(isolate, rhs, Object::ToNumber(rhs), Object);
623 } 550 }
624 return isolate->factory()->NewNumberFromInt(NumberToInt32(*lhs) ^ 551 return isolate->factory()->NewNumberFromInt(NumberToInt32(*lhs) ^
625 NumberToInt32(*rhs)); 552 NumberToInt32(*rhs));
626 } 553 }
627 554
628 555
629 Maybe<bool> Object::IsArray(Handle<Object> object) { 556 Maybe<bool> Object::IsArray(Handle<Object> object) {
630 if (object->IsJSArray()) return Just(true); 557 if (object->IsJSArray()) return Just(true);
(...skipping 19354 matching lines...) Expand 10 before | Expand all | Expand 10 after
19985 if (cell->value() != *new_value) { 19912 if (cell->value() != *new_value) {
19986 cell->set_value(*new_value); 19913 cell->set_value(*new_value);
19987 Isolate* isolate = cell->GetIsolate(); 19914 Isolate* isolate = cell->GetIsolate();
19988 cell->dependent_code()->DeoptimizeDependentCodeGroup( 19915 cell->dependent_code()->DeoptimizeDependentCodeGroup(
19989 isolate, DependentCode::kPropertyCellChangedGroup); 19916 isolate, DependentCode::kPropertyCellChangedGroup);
19990 } 19917 }
19991 } 19918 }
19992 19919
19993 } // namespace internal 19920 } // namespace internal
19994 } // namespace v8 19921 } // namespace v8
OLDNEW
« src/crankshaft/hydrogen-instructions.h ('K') | « src/objects.h ('k') | src/objects-inl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698