Remove JSNI from DateUtil.
Change-Id: I40b0c58875cce9aad73b5360a4e978bf852c2cd4
Review-Link: https://gwt-review.googlesource.com/#/c/18440/
diff --git a/dev/core/super/com/google/gwt/dev/jjs/intrinsic/com/google/gwt/lang/Runtime.java b/dev/core/super/com/google/gwt/dev/jjs/intrinsic/com/google/gwt/lang/Runtime.java
index 5118b40..8e6c5f8 100644
--- a/dev/core/super/com/google/gwt/dev/jjs/intrinsic/com/google/gwt/lang/Runtime.java
+++ b/dev/core/super/com/google/gwt/dev/jjs/intrinsic/com/google/gwt/lang/Runtime.java
@@ -176,11 +176,19 @@
@Runtime::prototypesByTypeId = {};
// Do polyfills for all methods expected in a modern browser.
- // Patch up Array.isArray for browsers that don't support the fast native check.
+
+ // Required by IE8
if (!Array.isArray) {
- Array.isArray = function (vArg) {
- return Object.prototype.toString.call(vArg) === "[object Array]";
- };
+ Array.isArray = function (vArg) {
+ return Object.prototype.toString.call(vArg) === "[object Array]";
+ };
+ }
+
+ // Required by IE8
+ if (!Date.now) {
+ Date.now = function now() {
+ return new Date().getTime();
+ };
}
}-*/;
diff --git a/user/super/com/google/gwt/emul/java/lang/System.java b/user/super/com/google/gwt/emul/java/lang/System.java
index a3b3062..5767122 100644
--- a/user/super/com/google/gwt/emul/java/lang/System.java
+++ b/user/super/com/google/gwt/emul/java/lang/System.java
@@ -22,8 +22,8 @@
import java.io.PrintStream;
import javaemul.internal.ArrayHelper;
-import javaemul.internal.DateUtil;
import javaemul.internal.HashCodes;
+import javaemul.internal.JsUtils;
import jsinterop.annotations.JsMethod;
@@ -93,7 +93,7 @@
}
public static long currentTimeMillis() {
- return (long) DateUtil.now();
+ return (long) JsUtils.getTime();
}
/**
diff --git a/user/super/com/google/gwt/emul/java/util/Random.java b/user/super/com/google/gwt/emul/java/util/Random.java
index c603378..4a7da06 100644
--- a/user/super/com/google/gwt/emul/java/util/Random.java
+++ b/user/super/com/google/gwt/emul/java/util/Random.java
@@ -37,7 +37,7 @@
import static javaemul.internal.InternalPreconditions.checkCriticalArgument;
import static javaemul.internal.InternalPreconditions.checkNotNull;
-import javaemul.internal.DateUtil;
+import javaemul.internal.JsUtils;
/**
* This class provides methods that generates pseudo-random numbers of different
@@ -114,7 +114,7 @@
public Random() {
// JsDate.now used instead of System.currentTimeMillis()
// as it returns a double in order to avoid the use os LongLib.
- double seed = uniqueSeed++ + DateUtil.now();
+ double seed = uniqueSeed++ + JsUtils.getTime();
int hi = (int) Math.floor(seed * twoToTheMinus24) & 0xffffff;
int lo = (int) (seed - (hi * twoToThe24));
setSeed(hi, lo);
diff --git a/user/super/com/google/gwt/emul/javaemul/internal/DateUtil.java b/user/super/com/google/gwt/emul/javaemul/internal/DateUtil.java
deleted file mode 100644
index 321bf95..0000000
--- a/user/super/com/google/gwt/emul/javaemul/internal/DateUtil.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * Copyright 2015 Google Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy of
- * the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-package javaemul.internal;
-
-/**
- * Simple Helper class to return Date.now.
- */
-public class DateUtil {
- /**
- * Returns the numeric value corresponding to the current time -
- * the number of milliseconds elapsed since 1 January 1970 00:00:00 UTC.
- */
- public static native double now() /*-{
- // IE8 does not have Date.now
- // when removing IE8 support we change this to Date.now()
- if (Date.now) {
- // Date.now vs Date.getTime() performance comparison:
- // http://jsperf.com/date-now-vs-new-date/8
- return Date.now();
- }
- return (new Date()).getTime();
- }-*/;
-}
\ No newline at end of file
diff --git a/user/super/com/google/gwt/emul/javaemul/internal/JsUtils.java b/user/super/com/google/gwt/emul/javaemul/internal/JsUtils.java
index 21a1d5a..164f5ff 100644
--- a/user/super/com/google/gwt/emul/javaemul/internal/JsUtils.java
+++ b/user/super/com/google/gwt/emul/javaemul/internal/JsUtils.java
@@ -24,9 +24,8 @@
*/
public class JsUtils {
- public static native int compare(String a, String b) /*-{
- return a == b ? 0 : (a < b ? -1 : 1);
- }-*/;
+ @JsMethod(namespace = "<window>", name = "Date.now")
+ public static native double getTime();
@JsMethod(namespace = "<window>")
public static native boolean isFinite(double d);