mirror of https://github.com/golang/go.git
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>
This commit is contained in:
parent
7b2f55d89f
commit
72ce047a6c
|
|
@ -16,13 +16,11 @@
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
const now = () => {
|
|
||||||
const [sec, nsec] = process.hrtime();
|
|
||||||
return sec * 1000 + nsec / 1000000;
|
|
||||||
};
|
|
||||||
global.performance = {
|
global.performance = {
|
||||||
timeOrigin: Date.now() - now(),
|
now() {
|
||||||
now: now,
|
const [sec, nsec] = process.hrtime();
|
||||||
|
return sec * 1000 + nsec / 1000000;
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
const util = require("util");
|
const util = require("util");
|
||||||
|
|
@ -116,6 +114,7 @@
|
||||||
return decoder.decode(new DataView(this._inst.exports.mem.buffer, saddr, len));
|
return decoder.decode(new DataView(this._inst.exports.mem.buffer, saddr, len));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const timeOrigin = Date.now() - performance.now();
|
||||||
this.importObject = {
|
this.importObject = {
|
||||||
go: {
|
go: {
|
||||||
// func wasmExit(code int32)
|
// func wasmExit(code int32)
|
||||||
|
|
@ -133,7 +132,7 @@
|
||||||
|
|
||||||
// func nanotime() int64
|
// func nanotime() int64
|
||||||
"runtime.nanotime": (sp) => {
|
"runtime.nanotime": (sp) => {
|
||||||
setInt64(sp + 8, (performance.timeOrigin + performance.now()) * 1000000);
|
setInt64(sp + 8, (timeOrigin + performance.now()) * 1000000);
|
||||||
},
|
},
|
||||||
|
|
||||||
// func walltime() (sec int64, nsec int32)
|
// func walltime() (sec int64, nsec int32)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue