Skip to content

Commit 72ce047

Browse files
neelancebradfitz
authored andcommitted
misc/wasm: remove use of performance.timeOrigin
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>
1 parent 7b2f55d commit 72ce047

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

misc/wasm/wasm_exec.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,11 @@
1616
},
1717
};
1818

19-
const now = () => {
20-
const [sec, nsec] = process.hrtime();
21-
return sec * 1000 + nsec / 1000000;
22-
};
2319
global.performance = {
24-
timeOrigin: Date.now() - now(),
25-
now: now,
20+
now() {
21+
const [sec, nsec] = process.hrtime();
22+
return sec * 1000 + nsec / 1000000;
23+
},
2624
};
2725

2826
const util = require("util");
@@ -116,6 +114,7 @@
116114
return decoder.decode(new DataView(this._inst.exports.mem.buffer, saddr, len));
117115
}
118116

117+
const timeOrigin = Date.now() - performance.now();
119118
this.importObject = {
120119
go: {
121120
// func wasmExit(code int32)
@@ -133,7 +132,7 @@
133132

134133
// func nanotime() int64
135134
"runtime.nanotime": (sp) => {
136-
setInt64(sp + 8, (performance.timeOrigin + performance.now()) * 1000000);
135+
setInt64(sp + 8, (timeOrigin + performance.now()) * 1000000);
137136
},
138137

139138
// func walltime() (sec int64, nsec int32)

0 commit comments

Comments
 (0)