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

Unified Diff: src/runtime.js

Issue 1109223004: [strong] Disallow implicit conversions for add (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/ic/ic.cc ('k') | test/mjsunit/strong/implicit-conversions.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/runtime.js
diff --git a/src/runtime.js b/src/runtime.js
index 9bb02aecb711ab6fbb932075a187905f9b72731f..7b291000e0e42badb2b3913a0465059db82ab463 100644
--- a/src/runtime.js
+++ b/src/runtime.js
@@ -160,6 +160,15 @@ function ADD(x) {
}
+//ECMA-262, section 11.6.1, page 50.
Dmitry Lomov (no reviews) 2015/04/30 08:43:59 This comment does not apply anymore I guess.
conradw 2015/04/30 09:19:33 Changed this and similar examples in other places.
+function ADD_STRONG(x) {
+ if (IS_NUMBER(this) && IS_NUMBER(x)) return %NumberAdd(this, x);
+ if (IS_STRING(this) && IS_STRING(x)) return %_StringAdd(this, x);
+
+ throw %MakeTypeError('strong_implicit_cast');
+}
+
+
// Left operand (this) is already a string.
function STRING_ADD_LEFT(y) {
if (!IS_STRING(y)) {
@@ -175,6 +184,15 @@ function STRING_ADD_LEFT(y) {
}
+//Left operand (this) is already a string.
+function STRING_ADD_LEFT_STRONG(y) {
+ if (IS_STRING(y)) {
+ return %_StringAdd(this, y);
+ }
+ throw %MakeTypeError('strong_implicit_cast');
+}
+
+
// Right operand (y) is already a string.
function STRING_ADD_RIGHT(y) {
var x = this;
@@ -191,6 +209,15 @@ function STRING_ADD_RIGHT(y) {
}
+//Right operand (y) is already a string.
+function STRING_ADD_RIGHT_STRONG(y) {
+ if (IS_STRING(this)) {
+ return %_StringAdd(this, y);
+ }
+ throw %MakeTypeError('strong_implicit_cast');
+}
+
+
// ECMA-262, section 11.6.2, page 50.
function SUB(y) {
var x = IS_NUMBER(this) ? this : %NonNumberToNumber(this);
« no previous file with comments | « src/ic/ic.cc ('k') | test/mjsunit/strong/implicit-conversions.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698