diff options
author | Xudong Zheng <7pkvm5aw@slicealias.com> | 2018-08-01 21:33:09 +0000 |
---|---|---|
committer | Brad Fitzpatrick <bradfitz@golang.org> | 2018-08-01 21:45:11 +0000 |
commit | 859a944ee2edf19bbc6d72ca52ccd9c3f6d687e2 (patch) | |
tree | a6d8a30565e86e74749cbaad75a0b71f68850292 /misc/wasm | |
parent | c29370c98ecfc7aa59f32c7a7897e50a0f6eb86b (diff) | |
download | go-859a944ee2edf19bbc6d72ca52ccd9c3f6d687e2.tar.gz go-859a944ee2edf19bbc6d72ca52ccd9c3f6d687e2.zip |
syscall/js: move callback helper code to misc/wasm to avoid using eval()
When using the compiled .wasm with misc/wasm/wasm_exec.js, we get an error message if the site prohibits eval() via the Content-Security-Policy header. This can be resolved by moving the callback helper code from src/syscall/js/callback.go to misc/wasm/wasm_exec.js.
Fixes #26748
Change-Id: I28f271b8a00631f4c66a1ac31305e85f20f9d420
GitHub-Last-Rev: a6a0268f38d36c198ca6b4ceb2e75cc8afec74eb
GitHub-Pull-Request: golang/go#26750
Reviewed-on: https://go-review.googlesource.com/127296
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Diffstat (limited to 'misc/wasm')
-rw-r--r-- | misc/wasm/wasm_exec.js | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/misc/wasm/wasm_exec.js b/misc/wasm/wasm_exec.js index f3772652da..94b9552c59 100644 --- a/misc/wasm/wasm_exec.js +++ b/misc/wasm/wasm_exec.js @@ -387,6 +387,28 @@ 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) { |