]> Cypherpunks repositories - gostls13.git/commitdiff
misc/wasm: remove use of performance.timeOrigin
authorRichard Musiol <mail@richard-musiol.de>
Wed, 13 Jun 2018 08:36:01 +0000 (10:36 +0200)
committerBrad Fitzpatrick <bradfitz@golang.org>
Wed, 13 Jun 2018 14:51:01 +0000 (14:51 +0000)
This commit changes wasm_exec.js to not depend on the existence of
performance.timeOrigin. The field is not yet supported on all
browsers, e.g. it is unavailable on Safari.

Change-Id: I6cd3834376c1c55424c29166fde1219f0d4d338f
Reviewed-on: https://go-review.googlesource.com/118617
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
misc/wasm/wasm_exec.js

index 151de2e2d16a5519585f259d8693335176de6638..de4cff7d2c09361954bcd944a87ddf6cabdca760 100755 (executable)
                        },
                };
 
-               const now = () => {
-                       const [sec, nsec] = process.hrtime();
-                       return sec * 1000 + nsec / 1000000;
-               };
                global.performance = {
-                       timeOrigin: Date.now() - now(),
-                       now: now,
+                       now() {
+                               const [sec, nsec] = process.hrtime();
+                               return sec * 1000 + nsec / 1000000;
+                       },
                };
 
                const util = require("util");
                                return decoder.decode(new DataView(this._inst.exports.mem.buffer, saddr, len));
                        }
 
+                       const timeOrigin = Date.now() - performance.now();
                        this.importObject = {
                                go: {
                                        // func wasmExit(code int32)
 
                                        // func nanotime() int64
                                        "runtime.nanotime": (sp) => {
-                                               setInt64(sp + 8, (performance.timeOrigin + performance.now()) * 1000000);
+                                               setInt64(sp + 8, (timeOrigin + performance.now()) * 1000000);
                                        },
 
                                        // func walltime() (sec int64, nsec int32)