mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-05 15:18:49 +00:00
Update wasm runtime.js
- polyfill `Math.ldexp` method - pass Math mathods streight through to exports object (they don't use `this`) - Don't pass `"utf-8"` encodings to `TextEncoder` and `TextDecoder` (encoder doesn't take params and decoder has utf-8 as default)
This commit is contained in:
Vendored
+13
-13
@@ -77,7 +77,7 @@ class WasmMemoryInterface {
|
|||||||
|
|
||||||
loadString(ptr, len) {
|
loadString(ptr, len) {
|
||||||
const bytes = this.loadBytes(ptr, len);
|
const bytes = this.loadBytes(ptr, len);
|
||||||
return new TextDecoder("utf-8").decode(bytes);
|
return new TextDecoder().decode(bytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
storeU8(addr, value) { this.mem.setUint8 (addr, value, true); }
|
storeU8(addr, value) { this.mem.setUint8 (addr, value, true); }
|
||||||
@@ -102,7 +102,7 @@ class WasmMemoryInterface {
|
|||||||
|
|
||||||
storeString(addr, value) {
|
storeString(addr, value) {
|
||||||
const bytes = this.loadBytes(addr, value.length);
|
const bytes = this.loadBytes(addr, value.length);
|
||||||
new TextEncoder("utf-8").encodeInto(value, bytes);
|
new TextEncoder().encodeInto(value, bytes);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -570,7 +570,7 @@ class WebGLInterface {
|
|||||||
if (buf_len > 0 && buf_ptr) {
|
if (buf_len > 0 && buf_ptr) {
|
||||||
let n = Math.min(buf_len, log.length);
|
let n = Math.min(buf_len, log.length);
|
||||||
log = log.substring(0, n);
|
log = log.substring(0, n);
|
||||||
this.mem.loadBytes(buf_ptr, buf_len).set(new TextEncoder("utf-8").encode(log))
|
this.mem.loadBytes(buf_ptr, buf_len).set(new TextEncoder().encode(log))
|
||||||
|
|
||||||
this.mem.storeInt(length_ptr, n);
|
this.mem.storeInt(length_ptr, n);
|
||||||
}
|
}
|
||||||
@@ -583,7 +583,7 @@ class WebGLInterface {
|
|||||||
if (buf_len > 0 && buf_ptr) {
|
if (buf_len > 0 && buf_ptr) {
|
||||||
let n = Math.min(buf_len, log.length);
|
let n = Math.min(buf_len, log.length);
|
||||||
log = log.substring(0, n);
|
log = log.substring(0, n);
|
||||||
this.mem.loadBytes(buf_ptr, buf_len).set(new TextEncoder("utf-8").encode(log))
|
this.mem.loadBytes(buf_ptr, buf_len).set(new TextEncoder().encode(log))
|
||||||
|
|
||||||
this.mem.storeInt(length_ptr, n);
|
this.mem.storeInt(length_ptr, n);
|
||||||
}
|
}
|
||||||
@@ -1149,7 +1149,7 @@ class WebGLInterface {
|
|||||||
|
|
||||||
let n = Math.min(buf_len, name.length);
|
let n = Math.min(buf_len, name.length);
|
||||||
name = name.substring(0, n);
|
name = name.substring(0, n);
|
||||||
this.mem.loadBytes(buf_ptr, buf_len).set(new TextEncoder("utf-8").encode(name))
|
this.mem.loadBytes(buf_ptr, buf_len).set(new TextEncoder().encode(name))
|
||||||
this.mem.storeInt(length_ptr, n);
|
this.mem.storeInt(length_ptr, n);
|
||||||
},
|
},
|
||||||
UniformBlockBinding: (program, uniformBlockIndex, uniformBlockBinding) => {
|
UniformBlockBinding: (program, uniformBlockIndex, uniformBlockBinding) => {
|
||||||
@@ -1342,14 +1342,14 @@ function odinSetupDefaultImports(wasmMemoryInterface, consoleElement) {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
sqrt: (x) => Math.sqrt(x),
|
sqrt: Math.sqrt,
|
||||||
sin: (x) => Math.sin(x),
|
sin: Math.sin,
|
||||||
cos: (x) => Math.cos(x),
|
cos: Math.cos,
|
||||||
pow: (x, power) => Math.pow(x, power),
|
pow: Math.pow,
|
||||||
fmuladd: (x, y, z) => x*y + z,
|
fmuladd: (x, y, z) => x*y + z,
|
||||||
ln: (x) => Math.log(x),
|
ln: Math.log,
|
||||||
exp: (x) => Math.exp(x),
|
exp: Math.exp,
|
||||||
ldexp: (x) => Math.ldexp(x),
|
ldexp: (x, exp) => x * Math.pow(2, exp),
|
||||||
},
|
},
|
||||||
"odin_dom": {
|
"odin_dom": {
|
||||||
init_event_raw: (ep) => {
|
init_event_raw: (ep) => {
|
||||||
@@ -1569,7 +1569,7 @@ function odinSetupDefaultImports(wasmMemoryInterface, consoleElement) {
|
|||||||
if (buf_len > 0 && buf_ptr) {
|
if (buf_len > 0 && buf_ptr) {
|
||||||
let n = Math.min(buf_len, str.length);
|
let n = Math.min(buf_len, str.length);
|
||||||
str = str.substring(0, n);
|
str = str.substring(0, n);
|
||||||
this.mem.loadBytes(buf_ptr, buf_len).set(new TextEncoder("utf-8").encode(str))
|
this.mem.loadBytes(buf_ptr, buf_len).set(new TextEncoder().encode(str))
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user