mirror of
https://github.com/golang/go
synced 2024-11-23 08:20:05 -07:00
syscall/js: move callback helper code to misc/wasm to avoid using eval()
This commit is contained in:
parent
b8669ef1ce
commit
a6a0268f38
@ -387,6 +387,28 @@
|
|||||||
await callbackPromise;
|
await callbackPromise;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static _makeCallbackHelper(id, pendingCallbacks, go) {
|
||||||
|
return function() {
|
||||||
|
pendingCallbacks.push({ id: id, args: arguments });
|
||||||
|
go._resolveCallbackPromise();
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
static _makeEventCallbackHelper(preventDefault, stopPropagation, stopImmediatePropagation, fn) {
|
||||||
|
return function(event) {
|
||||||
|
if (preventDefault) {
|
||||||
|
event.preventDefault();
|
||||||
|
}
|
||||||
|
if (stopPropagation) {
|
||||||
|
event.stopPropagation();
|
||||||
|
}
|
||||||
|
if (stopImmediatePropagation) {
|
||||||
|
event.stopImmediatePropagation();
|
||||||
|
}
|
||||||
|
fn(event);
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isNodeJS) {
|
if (isNodeJS) {
|
||||||
|
@ -8,33 +8,11 @@ package js
|
|||||||
|
|
||||||
import "sync"
|
import "sync"
|
||||||
|
|
||||||
var pendingCallbacks = Global().Get("Array").New()
|
var (
|
||||||
|
pendingCallbacks = Global().Get("Array").New()
|
||||||
var makeCallbackHelper = Global().Call("eval", `
|
makeCallbackHelper = Global().Get("Go").Get("_makeCallbackHelper")
|
||||||
(function(id, pendingCallbacks, go) {
|
makeEventCallbackHelper = Global().Get("Go").Get("_makeEventCallbackHelper")
|
||||||
return function() {
|
)
|
||||||
pendingCallbacks.push({ id: id, args: arguments });
|
|
||||||
go._resolveCallbackPromise();
|
|
||||||
};
|
|
||||||
})
|
|
||||||
`)
|
|
||||||
|
|
||||||
var makeEventCallbackHelper = Global().Call("eval", `
|
|
||||||
(function(preventDefault, stopPropagation, stopImmediatePropagation, fn) {
|
|
||||||
return function(event) {
|
|
||||||
if (preventDefault) {
|
|
||||||
event.preventDefault();
|
|
||||||
}
|
|
||||||
if (stopPropagation) {
|
|
||||||
event.stopPropagation();
|
|
||||||
}
|
|
||||||
if (stopImmediatePropagation) {
|
|
||||||
event.stopImmediatePropagation();
|
|
||||||
}
|
|
||||||
fn(event);
|
|
||||||
};
|
|
||||||
})
|
|
||||||
`)
|
|
||||||
|
|
||||||
var (
|
var (
|
||||||
callbacksMu sync.Mutex
|
callbacksMu sync.Mutex
|
||||||
|
Loading…
Reference in New Issue
Block a user