diff --git a/js/initcontext.go b/js/initcontext.go index 24bdda973c6b..98f16d9f1be1 100644 --- a/js/initcontext.go +++ b/js/initcontext.go @@ -128,7 +128,7 @@ func newBoundInitContext(base *InitContext, ctxPtr *context.Context, rt *goja.Ru // NewShare ... // TODO rename // TODO constructor? -func (i *InitContext) NewShare(name string, call goja.Callable) goja.Value { +func (i *InitContext) XShare(name string, call goja.Callable) goja.Value { i.sharesLock.Lock() defer i.sharesLock.Unlock() value, ok := i.shares[name] diff --git a/js/share.go b/js/share.go index 7288ab07c82f..9f99f35a6361 100644 --- a/js/share.go +++ b/js/share.go @@ -94,9 +94,11 @@ const arrayWrapperCode = `(function(val) { get: function(target, property, receiver) { switch (property){ case "length": - return target.length() + return target.length(); case Symbol.iterator: - return function() {return target.iterator()} + return function() { + return target.iterator(); + }; } var i = parseInt(property); if (isNaN(i)) { @@ -106,5 +108,5 @@ const arrayWrapperCode = `(function(val) { return target.get(i); } }; - return new Proxy(val, arrayHandler) + return new Proxy(val, arrayHandler); })` diff --git a/js/share_test.go b/js/share_test.go index f53ef7b30c21..46f7330962c9 100644 --- a/js/share_test.go +++ b/js/share_test.go @@ -45,34 +45,34 @@ function generateArray() { return arr; } -var s = newShare("something", generateArray); +var s = new Share("something", generateArray); var er = ""; try { - var p = newShare("wat", function() {return "whatever"}); + var p = new Share("wat", function() {return "whatever"}); throw "the previous line should've errored"; } catch (e) { if (!e.toString().includes("only arrays can be made into shared objects")) { - er = "wrong error " + e.toString() + er = "wrong error " + e.toString(); } } if (er != "") { - throw er + throw er; } exports.default = function() { if (s[2] !== "something2") { - throw new Error("bad s[2]="+s[2]) + throw new Error("bad s[2]="+s[2]); } if (s.length != 50) { - throw new Error("bad length " +_s.length) + throw new Error("bad length " +_s.length); } var i = 0; for (var v of s) { if (v !== "something"+i) { - throw new Error("bad v="+v+" for i="+i) + throw new Error("bad v="+v+" for i="+i); } i++; } @@ -83,29 +83,29 @@ exports.default = function() { try { s.something = 21 - throw "the previous line should've errored s.something = 21" + throw "the previous line should've errored s.something = 21"; } catch(e) { if (!e.toString().includes("Host object field something cannot be made configurable")) { - er = "wrong error " + e.toString() + er = "wrong error " + e.toString(); } } if (er != "") { - throw er + throw er; } try { - s[1]= "21" + s[1]= "21"; - throw "the previous line should've errored" + throw "the previous line should've errored"; } catch(e) { if (!e.toString().includes("Host object field 1 cannot be made configurable")) { - er = "wrong error " + e.toString() + er = "wrong error " + e.toString(); } } if (er != "") { - throw er + throw er; } }`