Skip to content

Commit

Permalink
more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mstoykov committed Dec 9, 2020
1 parent d382235 commit 1b56ea9
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 18 deletions.
22 changes: 5 additions & 17 deletions js/share.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,30 +92,18 @@ func (s sharedArray) Iterator() *sharedArrayIterator {
const arrayWrapperCode = `(function(val) {
var arrayHandler = {
get: function(target, property, receiver) {
// console.log("accessing ", property)
switch (property){
case "length":
return target.length()
case Symbol.iterator:
return function() {return target.iterator()}
/*
return function(){
var index = 0;
return {
"next": function() {
if (index >= target.length()) {
return {done: true}
}
var result = {value:target.get(index)};
index++;
return result;
}
}
}
*/
var i = parseInt(property);
if (isNaN(i)) {
return undefined;
}
return target.get(property);
return target.get(i);
}
};
return new Proxy(val, arrayHandler)
Expand Down
47 changes: 46 additions & 1 deletion js/share_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import (
)

func TestInitContextNewShareable(t *testing.T) {
data := `
data := `'use strict';
function generateArray() {
console.log("once");
var n = 50;
Expand All @@ -47,6 +47,20 @@ function generateArray() {
var s = newShare("something", generateArray);
var er = "";
try {
var p = newShare("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()
}
}
if (er != "") {
throw er
}
exports.default = function() {
if (s[2] !== "something2") {
throw new Error("bad s[2]="+s[2])
Expand All @@ -62,6 +76,37 @@ exports.default = function() {
}
i++;
}
if (s.something != undefined) {
throw "s.something should've been undefined but was " + s.something;
}
try {
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()
}
}
if (er != "") {
throw er
}
try {
s[1]= "21"
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()
}
}
if (er != "") {
throw er
}
}`

logger := logrus.New()
Expand Down

0 comments on commit 1b56ea9

Please sign in to comment.