Reviewers: Dmitry Lomov (chromium),

Description:
Harmony: implement Math.sign.

[email protected]
BUG=v8:2938

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

SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge

Affected files (+41, -45 lines):
  M src/bootstrapper.cc
  M src/flag-definitions.h
  A + src/harmony-math.js
  A + test/mjsunit/harmony/math-sign.js
  M tools/gyp/v8.gyp


Index: src/bootstrapper.cc
diff --git a/src/bootstrapper.cc b/src/bootstrapper.cc
index c48385ce11ccec616e5435ee198b8b0d55ba23a6..234a2118bdd7002189906df3e21f6446869f594e 100644
--- a/src/bootstrapper.cc
+++ b/src/bootstrapper.cc
@@ -2067,6 +2067,11 @@ bool Genesis::InstallExperimentalNatives() {
                "native harmony-array.js") == 0) {
       if (!CompileExperimentalBuiltin(isolate(), i)) return false;
     }
+    if (FLAG_harmony_maths &&
+        strcmp(ExperimentalNatives::GetScriptName(i).start(),
+               "native harmony-math.js") == 0) {
+      if (!CompileExperimentalBuiltin(isolate(), i)) return false;
+    }
   }

   InstallExperimentalNativeFunctions();
Index: src/flag-definitions.h
diff --git a/src/flag-definitions.h b/src/flag-definitions.h
index 379ae698ca7488850d20dd537611308ab0fdc564..6bd18c84291a75a5a7b8b62cfbd1989e7af70167 100644
--- a/src/flag-definitions.h
+++ b/src/flag-definitions.h
@@ -182,6 +182,7 @@ DEFINE_bool(harmony_numeric_literals, false,
             "enable harmony numeric literals (0o77, 0b11)")
 DEFINE_bool(harmony_strings, false, "enable harmony string")
 DEFINE_bool(harmony_arrays, false, "enable harmony arrays")
+DEFINE_bool(harmony_maths, false, "enable harmony math functions")
 DEFINE_bool(harmony, false, "enable all harmony features (except typeof)")
 DEFINE_implication(harmony, harmony_scoping)
 DEFINE_implication(harmony, harmony_modules)
@@ -194,6 +195,7 @@ DEFINE_implication(harmony, harmony_iteration)
 DEFINE_implication(harmony, harmony_numeric_literals)
 DEFINE_implication(harmony, harmony_strings)
 DEFINE_implication(harmony, harmony_arrays)
+DEFINE_implication(harmony, harmony_maths)
 DEFINE_implication(harmony_modules, harmony_scoping)
 DEFINE_implication(harmony_observation, harmony_collections)

Index: src/harmony-math.js
diff --git a/test/mjsunit/regress/regress-2489.js b/src/harmony-math.js
similarity index 79%
copy from test/mjsunit/regress/regress-2489.js
copy to src/harmony-math.js
index 882c4f794a88e24d1d64e86a466b27c39f51e625..2e9b42a75e7cf368af023c29baaf9cd24663a3b8 100644
--- a/test/mjsunit/regress/regress-2489.js
+++ b/src/harmony-math.js
@@ -25,26 +25,25 @@
 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

-// Flags: --allow-natives-syntax
+'use strict';

-"use strict";
-
-function f(a, b) {
-  return g("c", "d");
+// ES6 draft 09-27-13, section 20.2.2.28.
+function MathSign(x) {
+  if (!IS_NUMBER(x)) x = NonNumberToNumber(x);
+  if (x > 0) return 1;
+  if (x < 0) return -1;
+  if (x === 0) return x;
+  return NAN;
 }

-function g(a, b) {
-  g.constructor.apply(this, arguments);
-}

-g.constructor = function(a, b) {
-  assertEquals("c", a);
-  assertEquals("d", b);
+function ExtendMath() {
+  %CheckIsBootstrapping();
+
+  // Set up the non-enumerable functions on the Math object.
+  InstallFunctions($Math, DONT_ENUM, $Array(
+    "sign", MathSign
+  ));
 }

-f("a", "b");
-f("a", "b");
-%OptimizeFunctionOnNextCall(f);
-f("a", "b");
-g.x = "deopt";
-f("a", "b");
+ExtendMath();
Index: test/mjsunit/harmony/math-sign.js
diff --git a/src/hydrogen-bch.h b/test/mjsunit/harmony/math-sign.js
similarity index 68%
copy from src/hydrogen-bch.h
copy to test/mjsunit/harmony/math-sign.js
index a22dacdd4229748e2735b3c0d8519c927b2f617d..4ace53d4ffe6ecb67cb8356e2408ef7f05e924a8 100644
--- a/src/hydrogen-bch.h
+++ b/test/mjsunit/harmony/math-sign.js
@@ -25,31 +25,20 @@
 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

-#ifndef V8_HYDROGEN_BCH_H_
-#define V8_HYDROGEN_BCH_H_
-
-#include "hydrogen.h"
-
-namespace v8 {
-namespace internal {
-
-
-class HBoundsCheckHoistingPhase : public HPhase {
- public:
-  explicit HBoundsCheckHoistingPhase(HGraph* graph)
-      : HPhase("H_Bounds checks hoisting", graph) { }
-
-  void Run() {
-    HoistRedundantBoundsChecks();
-  }
-
- private:
-  void HoistRedundantBoundsChecks();
-
-  DISALLOW_COPY_AND_ASSIGN(HBoundsCheckHoistingPhase);
-};
-
-
-} }  // namespace v8::internal
-
-#endif  // V8_HYDROGEN_BCE_H_
+// Flags: --harmony-maths
+
+assertEquals("Infinity", String(1/Math.sign(0)));
+assertEquals("-Infinity", String(1/Math.sign(-0)));
+assertEquals(1, Math.sign(100));
+assertEquals(-1, Math.sign(-199));
+assertEquals(1, Math.sign(100.1));
+assertTrue(isNaN(Math.sign("abc")));
+assertTrue(isNaN(Math.sign({})));
+assertEquals(0, Math.sign([]));
+assertEquals(1, Math.sign([1]));
+assertEquals(-1, Math.sign([-100.1]));
+assertTrue(isNaN(Math.sign([1, 1])));
+assertEquals(1, Math.sign({ toString: function() { return "100"; } }));
+assertEquals(1, Math.sign({ toString: function() { return 100; } }));
+assertEquals(-1, Math.sign({ valueOf: function() { return -1.1; } }));
+assertEquals(-1, Math.sign({ valueOf: function() { return "-1.1"; } }));
Index: tools/gyp/v8.gyp
diff --git a/tools/gyp/v8.gyp b/tools/gyp/v8.gyp
index 94b9bc00d0d5f37e8be4beb2fb182a788953e5a8..22fcf94566f93c073f89eae287ead198a26521a8 100644
--- a/tools/gyp/v8.gyp
+++ b/tools/gyp/v8.gyp
@@ -936,6 +936,7 @@
           '../../src/array-iterator.js',
           '../../src/harmony-string.js',
           '../../src/harmony-array.js',
+          '../../src/harmony-math.js'
         ],
       },
       'actions': [


--
--
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/groups/opt_out.

Reply via email to