Reviewers: rossberg,

Message:
PTAL

Description:
[es6] When comparing two symbols we may need to throw a TypeError

When comparing a symbol to istself using <, <=, > or >= we need to
throw a TypeError. This is correctly handled in the runtime function
so if we are comparing a symbol fall back to use the runtime.

BUG=v8:4073
LOG=Y
[email protected]

Please review this at https://codereview.chromium.org/1125783002/

Base URL: https://chromium.googlesource.com/v8/v8.git@master

Affected files (+48, -0 lines):
  M src/arm/code-stubs-arm.cc
  M src/arm64/code-stubs-arm64.cc
  M src/ia32/code-stubs-ia32.cc
  M src/mips/code-stubs-mips.cc
  M src/mips64/code-stubs-mips64.cc
  M src/ppc/code-stubs-ppc.cc
  M src/x64/code-stubs-x64.cc
  M src/x87/code-stubs-x87.cc
  M test/mjsunit/es6/symbols.js


Index: src/arm/code-stubs-arm.cc
diff --git a/src/arm/code-stubs-arm.cc b/src/arm/code-stubs-arm.cc
index d0ff12a8d8bb347f390f687637270122961243cb..08804b7c098df8929ef83761cb39f9fe6a94a2a9 100644
--- a/src/arm/code-stubs-arm.cc
+++ b/src/arm/code-stubs-arm.cc
@@ -253,6 +253,8 @@ static void EmitIdenticalObjectComparison(MacroAssembler* masm,
   if (cond == lt || cond == gt) {
     __ CompareObjectType(r0, r4, r4, FIRST_SPEC_OBJECT_TYPE);
     __ b(ge, slow);
+    __ CompareObjectType(r0, r4, r4, SYMBOL_TYPE);
+    __ b(eq, slow);
   } else {
     __ CompareObjectType(r0, r4, r4, HEAP_NUMBER_TYPE);
     __ b(eq, &heap_number);
Index: src/arm64/code-stubs-arm64.cc
diff --git a/src/arm64/code-stubs-arm64.cc b/src/arm64/code-stubs-arm64.cc
index 59912af8f5f46a7bc6eb604083635e784ca6369d..1c6972280e138a8121247c378df3c3040cfdb5ef 100644
--- a/src/arm64/code-stubs-arm64.cc
+++ b/src/arm64/code-stubs-arm64.cc
@@ -224,6 +224,7 @@ static void EmitIdenticalObjectComparison(MacroAssembler* masm,
   if ((cond == lt) || (cond == gt)) {
__ JumpIfObjectType(right, scratch, scratch, FIRST_SPEC_OBJECT_TYPE, slow,
                         ge);
+    __ JumpIfObjectType(right, scratch, scratch, SYMBOL_TYPE, slow, eq);
   } else if (cond == eq) {
     __ JumpIfHeapNumber(right, &heap_number);
   } else {
Index: src/ia32/code-stubs-ia32.cc
diff --git a/src/ia32/code-stubs-ia32.cc b/src/ia32/code-stubs-ia32.cc
index 90e3672a91d8315adb4074d3c2049c9dfa74a8fa..379c1c8bf277a6e86860d6ff659ea7f6470ded5d 100644
--- a/src/ia32/code-stubs-ia32.cc
+++ b/src/ia32/code-stubs-ia32.cc
@@ -1710,6 +1710,9 @@ void CompareICStub::GenerateGeneric(MacroAssembler* masm) {
       // Call runtime on identical JSObjects.  Otherwise return equal.
       __ CmpObjectType(eax, FIRST_SPEC_OBJECT_TYPE, ecx);
       __ j(above_equal, &not_identical);
+ // Call runtime on identical symbols since we need to throw a TypeError.
+      __ CmpObjectType(eax, SYMBOL_TYPE, ecx);
+      __ j(equal, &not_identical);
     }
     __ Move(eax, Immediate(Smi::FromInt(EQUAL)));
     __ ret(0);
Index: src/mips/code-stubs-mips.cc
diff --git a/src/mips/code-stubs-mips.cc b/src/mips/code-stubs-mips.cc
index ca0d2e94c08e3b5bdae24be13d9c6a3197715ddb..dc68371b90d736fc987ee0494f97051b8a928cf4 100644
--- a/src/mips/code-stubs-mips.cc
+++ b/src/mips/code-stubs-mips.cc
@@ -294,6 +294,8 @@ static void EmitIdenticalObjectComparison(MacroAssembler* masm,
   if (cc == less || cc == greater) {
     __ GetObjectType(a0, t4, t4);
     __ Branch(slow, greater, t4, Operand(FIRST_SPEC_OBJECT_TYPE));
+    __ GetObjectType(a0, t4, t4);
+    __ Branch(slow, eq, t4, Operand(SYMBOL_TYPE));
   } else {
     __ GetObjectType(a0, t4, t4);
     __ Branch(&heap_number, eq, t4, Operand(HEAP_NUMBER_TYPE));
Index: src/mips64/code-stubs-mips64.cc
diff --git a/src/mips64/code-stubs-mips64.cc b/src/mips64/code-stubs-mips64.cc index 9cfef7d8d627b5b47c359ebddf5e29df9de01a6f..c93c96d65b8fa2b79794bbcd25fcc35280956069 100644
--- a/src/mips64/code-stubs-mips64.cc
+++ b/src/mips64/code-stubs-mips64.cc
@@ -290,6 +290,8 @@ static void EmitIdenticalObjectComparison(MacroAssembler* masm,
   if (cc == less || cc == greater) {
     __ GetObjectType(a0, t0, t0);
     __ Branch(slow, greater, t0, Operand(FIRST_SPEC_OBJECT_TYPE));
+    __ GetObjectType(a0, t0, t0);
+    __ Branch(slow, eq, t0, Operand(SYMBOL_TYPE));
   } else {
     __ GetObjectType(a0, t0, t0);
     __ Branch(&heap_number, eq, t0, Operand(HEAP_NUMBER_TYPE));
Index: src/ppc/code-stubs-ppc.cc
diff --git a/src/ppc/code-stubs-ppc.cc b/src/ppc/code-stubs-ppc.cc
index f7c8e65a06a2de4298061a61ac1c74de49abfe0c..8d07b928e05b163ac9116926bf9e1d5f9193c928 100644
--- a/src/ppc/code-stubs-ppc.cc
+++ b/src/ppc/code-stubs-ppc.cc
@@ -262,6 +262,8 @@ static void EmitIdenticalObjectComparison(MacroAssembler* masm, Label* slow,
   if (cond == lt || cond == gt) {
     __ CompareObjectType(r3, r7, r7, FIRST_SPEC_OBJECT_TYPE);
     __ bge(slow);
+    __ CompareObjectType(r3, r7, r7, SYMBOL_TYPE);
+    __ beq(slow);
   } else {
     __ CompareObjectType(r3, r7, r7, HEAP_NUMBER_TYPE);
     __ beq(&heap_number);
Index: src/x64/code-stubs-x64.cc
diff --git a/src/x64/code-stubs-x64.cc b/src/x64/code-stubs-x64.cc
index 401db6b3fbfc6af98c7f0e3eee01997106eb3127..7a9c12e2d2f95b037af33b2c3e950f866cfddd03 100644
--- a/src/x64/code-stubs-x64.cc
+++ b/src/x64/code-stubs-x64.cc
@@ -1578,6 +1578,9 @@ void CompareICStub::GenerateGeneric(MacroAssembler* masm) {
       // Call runtime on identical objects.  Otherwise return equal.
       __ CmpObjectType(rax, FIRST_SPEC_OBJECT_TYPE, rcx);
       __ j(above_equal, &not_identical, Label::kNear);
+ // Call runtime on identical symbols since we need to throw a TypeError.
+      __ CmpObjectType(rax, SYMBOL_TYPE, rcx);
+      __ j(equal, &not_identical, Label::kNear);
     }
     __ Set(rax, EQUAL);
     __ ret(0);
Index: src/x87/code-stubs-x87.cc
diff --git a/src/x87/code-stubs-x87.cc b/src/x87/code-stubs-x87.cc
index cba6734a6f9ccf4811a6480116d284f9efa6c4da..335837abdf14ccb0226c47d5ca1af9b26a69e2aa 100644
--- a/src/x87/code-stubs-x87.cc
+++ b/src/x87/code-stubs-x87.cc
@@ -1385,6 +1385,9 @@ void CompareICStub::GenerateGeneric(MacroAssembler* masm) {
       // Call runtime on identical JSObjects.  Otherwise return equal.
       __ CmpObjectType(eax, FIRST_SPEC_OBJECT_TYPE, ecx);
       __ j(above_equal, &not_identical);
+ // Call runtime on identical symbols since we need to throw a TypeError.
+      __ CmpObjectType(eax, SYMBOL_TYPE, ecx);
+      __ j(equal, &not_identical);
     }
     __ Move(eax, Immediate(Smi::FromInt(EQUAL)));
     __ ret(0);
Index: test/mjsunit/es6/symbols.js
diff --git a/test/mjsunit/es6/symbols.js b/test/mjsunit/es6/symbols.js
index 46c3daba8a177c6dce414b1efe6e1c334e2aa147..7203f67a87ca6a5229c03169e2986d5712f9608d 100644
--- a/test/mjsunit/es6/symbols.js
+++ b/test/mjsunit/es6/symbols.js
@@ -504,3 +504,33 @@ function TestGetOwnPropertySymbolsOnPrimitives() {
   assertEquals(Object.getOwnPropertySymbols("OK"), []);
 }
 TestGetOwnPropertySymbolsOnPrimitives();
+
+
+function TestComparison() {
+  function f() {
+    var a = Symbol();
+    a < a;
+    a > a;
+    a <= a;
+    a >= a;
+  }
+
+  assertThrows(f, TypeError);
+  %OptimizeFunctionOnNextCall(f);
+  assertThrows(f, TypeError);
+  assertThrows(f, TypeError);
+
+  function g() {
+    var a = Symbol();
+    var b = Symbol();
+    a < b;
+    a > b;
+    a <= b;
+    a >= b;
+  }
+  assertThrows(g, TypeError);
+  %OptimizeFunctionOnNextCall(g);
+  assertThrows(g, TypeError);
+  assertThrows(g, TypeError);
+}
+TestComparison();


--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to