From 60d0add32d806c1268e338250217a24172891c09 Mon Sep 17 00:00:00 2001 From: Yuta Saito Date: Sun, 18 Jul 2021 09:51:25 +0900 Subject: [PATCH 1/7] Update package-lock.json --- IntegrationTests/package-lock.json | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/IntegrationTests/package-lock.json b/IntegrationTests/package-lock.json index 3c01ae5ac..50727e508 100644 --- a/IntegrationTests/package-lock.json +++ b/IntegrationTests/package-lock.json @@ -12,7 +12,7 @@ }, "..": { "name": "javascript-kit-swift", - "version": "0.9.0", + "version": "0.10.1", "license": "MIT", "devDependencies": { "prettier": "2.1.2", @@ -22,12 +22,14 @@ "../node_modules/prettier": { "version": "2.1.2", "resolved": "https://registry.npmjs.org/prettier/-/prettier-2.1.2.tgz", - "integrity": "sha512-16c7K+x4qVlJg9rEbXl7HEGmQyZlG4R9AgP+oHKRMsMsuk8s+ATStlf1NpDqyBI1HpVyfjLOeMhH2LvuNvV5Vg==" + "integrity": "sha512-16c7K+x4qVlJg9rEbXl7HEGmQyZlG4R9AgP+oHKRMsMsuk8s+ATStlf1NpDqyBI1HpVyfjLOeMhH2LvuNvV5Vg==", + "dev": true }, "../node_modules/typescript": { "version": "4.0.2", "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.0.2.tgz", - "integrity": "sha512-e4ERvRV2wb+rRZ/IQeb3jm2VxBsirQLpQhdxplZ2MEzGvDkkMmPglecnNDfSUBivMjP93vRbngYYDQqQ/78bcQ==" + "integrity": "sha512-e4ERvRV2wb+rRZ/IQeb3jm2VxBsirQLpQhdxplZ2MEzGvDkkMmPglecnNDfSUBivMjP93vRbngYYDQqQ/78bcQ==", + "dev": true }, "node_modules/@wasmer/wasi": { "version": "0.12.0", @@ -310,12 +312,14 @@ "prettier": { "version": "2.1.2", "resolved": "https://registry.npmjs.org/prettier/-/prettier-2.1.2.tgz", - "integrity": "sha512-16c7K+x4qVlJg9rEbXl7HEGmQyZlG4R9AgP+oHKRMsMsuk8s+ATStlf1NpDqyBI1HpVyfjLOeMhH2LvuNvV5Vg==" + "integrity": "sha512-16c7K+x4qVlJg9rEbXl7HEGmQyZlG4R9AgP+oHKRMsMsuk8s+ATStlf1NpDqyBI1HpVyfjLOeMhH2LvuNvV5Vg==", + "dev": true }, "typescript": { "version": "4.0.2", "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.0.2.tgz", - "integrity": "sha512-e4ERvRV2wb+rRZ/IQeb3jm2VxBsirQLpQhdxplZ2MEzGvDkkMmPglecnNDfSUBivMjP93vRbngYYDQqQ/78bcQ==" + "integrity": "sha512-e4ERvRV2wb+rRZ/IQeb3jm2VxBsirQLpQhdxplZ2MEzGvDkkMmPglecnNDfSUBivMjP93vRbngYYDQqQ/78bcQ==", + "dev": true } } }, From 42646205aa31070ed1a8311a9bdfc477ab6337ef Mon Sep 17 00:00:00 2001 From: Yuta Saito Date: Sun, 18 Jul 2021 09:52:20 +0900 Subject: [PATCH 2/7] Ensure that setting nested prop works --- IntegrationTests/TestSuites/Sources/PrimaryTests/main.swift | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/IntegrationTests/TestSuites/Sources/PrimaryTests/main.swift b/IntegrationTests/TestSuites/Sources/PrimaryTests/main.swift index e93dfc1b6..755b41453 100644 --- a/IntegrationTests/TestSuites/Sources/PrimaryTests/main.swift +++ b/IntegrationTests/TestSuites/Sources/PrimaryTests/main.swift @@ -617,12 +617,15 @@ try test("Error") { } try test("JSValue accessor") { - let globalObject1 = JSObject.global.globalObject1 + var globalObject1 = JSObject.global.globalObject1 try expectEqual(globalObject1.prop_1.nested_prop, .number(1)) try expectEqual(globalObject1.object!.prop_1.object!.nested_prop, .number(1)) try expectEqual(globalObject1.prop_4[0], .number(3)) try expectEqual(globalObject1.prop_4[1], .number(4)) + + globalObject1.prop_1.nested_prop = "bar" + try expectEqual(globalObject1.prop_1.nested_prop, .string("bar")) } try test("Exception") { From 8c576378071e9e115728a7333ed1efd5bc0ae40c Mon Sep 17 00:00:00 2001 From: Yuta Saito Date: Sun, 18 Jul 2021 11:22:59 +0900 Subject: [PATCH 3/7] Fix example Makefile --- Example/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Example/Makefile b/Example/Makefile index 7be06db0e..acfc5eadc 100644 --- a/Example/Makefile +++ b/Example/Makefile @@ -7,7 +7,7 @@ JavaScriptKitExample: dist/JavaScriptKitExample.wasm: JavaScriptKitExample mkdir -p dist - cp ./JavaScriptKitExample/.build/debug/JavaScriptKitExample $@ + cp ./JavaScriptKitExample/.build/debug/JavaScriptKitExample.wasm $@ node_modules: npm ci From ebf19c653ca924870a1a57472dfe973c8da6ef94 Mon Sep 17 00:00:00 2001 From: Yuta Saito Date: Sun, 18 Jul 2021 11:29:20 +0900 Subject: [PATCH 4/7] Note that fatal error outputs are expected --- IntegrationTests/TestSuites/Sources/PrimaryTests/main.swift | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/IntegrationTests/TestSuites/Sources/PrimaryTests/main.swift b/IntegrationTests/TestSuites/Sources/PrimaryTests/main.swift index 755b41453..e165b8b92 100644 --- a/IntegrationTests/TestSuites/Sources/PrimaryTests/main.swift +++ b/IntegrationTests/TestSuites/Sources/PrimaryTests/main.swift @@ -200,7 +200,9 @@ try test("Closure Lifetime") { } c1.release() // Call a released closure + print("======= BEGIN OF EXPECTED FATAL ERROR =====") _ = try expectThrow(try evalClosure.throws(c1)) + print("======= END OF EXPECTED FATAL ERROR =======") } do { @@ -209,7 +211,9 @@ try test("Closure Lifetime") { _ = JSClosure { _ in .undefined } return .undefined } + print("======= BEGIN OF EXPECTED FATAL ERROR =====") _ = try expectThrow(try evalClosure.throws(c1)) + print("======= END OF EXPECTED FATAL ERROR =======") c1.release() } @@ -219,7 +223,9 @@ try test("Closure Lifetime") { } try expectEqual(evalClosure(c1), .boolean(true)) // second call will cause `fatalError` that can be caught as a JavaScript exception + print("======= BEGIN OF EXPECTED FATAL ERROR =====") _ = try expectThrow(try evalClosure.throws(c1)) + print("======= END OF EXPECTED FATAL ERROR =======") // OneshotClosure won't call fatalError even if it's deallocated before `release` } } From 3fbb3ea158fa38fe5d27cde34b62e27da5efc323 Mon Sep 17 00:00:00 2001 From: Yuta Saito Date: Sun, 18 Jul 2021 11:30:42 +0900 Subject: [PATCH 5/7] npm audit fix --- Example/package-lock.json | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/Example/package-lock.json b/Example/package-lock.json index 8e41ce72b..dedf0fe55 100644 --- a/Example/package-lock.json +++ b/Example/package-lock.json @@ -1673,9 +1673,9 @@ "dev": true }, "node_modules/dns-packet": { - "version": "1.3.1", - "resolved": "https://registry.npmjs.org/dns-packet/-/dns-packet-1.3.1.tgz", - "integrity": "sha512-0UxfQkMhYAUaZI+xrNZOz/as5KgDU0M/fQ9b6SpkyLbk3GEswDi6PADJVaYJradtRVsRIlF1zLyOodbcTCDzUg==", + "version": "1.3.4", + "resolved": "https://registry.npmjs.org/dns-packet/-/dns-packet-1.3.4.tgz", + "integrity": "sha512-BQ6F4vycLXBvdrJZ6S3gZewt6rcrks9KBgM9vrhW+knGRqc8uEdT7fuCwloc7nny5xNoMJ17HGH0R/6fpo8ECA==", "dev": true, "dependencies": { "ip": "^1.1.0", @@ -6906,9 +6906,9 @@ "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=" }, "node_modules/ws": { - "version": "6.2.1", - "resolved": "https://registry.npmjs.org/ws/-/ws-6.2.1.tgz", - "integrity": "sha512-GIyAXC2cB7LjvpgMt9EKS2ldqr0MTrORaleiOno6TweZ6r3TKtoFQWay/2PceJ3RuBasOHzXNn5Lrw1X0bEjqA==", + "version": "6.2.2", + "resolved": "https://registry.npmjs.org/ws/-/ws-6.2.2.tgz", + "integrity": "sha512-zmhltoSR8u1cnDsD43TX59mzoMZsLKqUweyYBAIvTngR3shc0W6aOZylZmq/7hqyVxPdi+5Ud2QInblgyE72fw==", "dev": true, "dependencies": { "async-limiter": "~1.0.0" @@ -8397,9 +8397,9 @@ "dev": true }, "dns-packet": { - "version": "1.3.1", - "resolved": "https://registry.npmjs.org/dns-packet/-/dns-packet-1.3.1.tgz", - "integrity": "sha512-0UxfQkMhYAUaZI+xrNZOz/as5KgDU0M/fQ9b6SpkyLbk3GEswDi6PADJVaYJradtRVsRIlF1zLyOodbcTCDzUg==", + "version": "1.3.4", + "resolved": "https://registry.npmjs.org/dns-packet/-/dns-packet-1.3.4.tgz", + "integrity": "sha512-BQ6F4vycLXBvdrJZ6S3gZewt6rcrks9KBgM9vrhW+knGRqc8uEdT7fuCwloc7nny5xNoMJ17HGH0R/6fpo8ECA==", "dev": true, "requires": { "ip": "^1.1.0", @@ -12764,9 +12764,9 @@ "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=" }, "ws": { - "version": "6.2.1", - "resolved": "https://registry.npmjs.org/ws/-/ws-6.2.1.tgz", - "integrity": "sha512-GIyAXC2cB7LjvpgMt9EKS2ldqr0MTrORaleiOno6TweZ6r3TKtoFQWay/2PceJ3RuBasOHzXNn5Lrw1X0bEjqA==", + "version": "6.2.2", + "resolved": "https://registry.npmjs.org/ws/-/ws-6.2.2.tgz", + "integrity": "sha512-zmhltoSR8u1cnDsD43TX59mzoMZsLKqUweyYBAIvTngR3shc0W6aOZylZmq/7hqyVxPdi+5Ud2QInblgyE72fw==", "dev": true, "requires": { "async-limiter": "~1.0.0" From c29d3f8c3ccae2d78e70720028d46be0ed795f89 Mon Sep 17 00:00:00 2001 From: Yuta Saito Date: Sun, 18 Jul 2021 11:49:07 +0900 Subject: [PATCH 6/7] Add failing tests for TODO --- .../TestSuites/Sources/PrimaryTests/main.swift | 10 ++++++++++ IntegrationTests/bin/primary-tests.js | 16 ++++++++++++++-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/IntegrationTests/TestSuites/Sources/PrimaryTests/main.swift b/IntegrationTests/TestSuites/Sources/PrimaryTests/main.swift index e165b8b92..29052720b 100644 --- a/IntegrationTests/TestSuites/Sources/PrimaryTests/main.swift +++ b/IntegrationTests/TestSuites/Sources/PrimaryTests/main.swift @@ -632,6 +632,16 @@ try test("JSValue accessor") { globalObject1.prop_1.nested_prop = "bar" try expectEqual(globalObject1.prop_1.nested_prop, .string("bar")) + + /* TODO: Fix https://github.com/swiftwasm/JavaScriptKit/issues/132 and un-comment this test + `nested` should not be set again to `target.nested` by `target.nested.prop = .number(1)` + + let observableObj = globalObject1.observable_obj.object! + observableObj.set_called = .boolean(false) + observableObj.target.nested.prop = .number(1) + try expectEqual(observableObj.set_called, .boolean(false)) + + */ } try test("Exception") { diff --git a/IntegrationTests/bin/primary-tests.js b/IntegrationTests/bin/primary-tests.js index 6cb3aea3c..79c62776a 100644 --- a/IntegrationTests/bin/primary-tests.js +++ b/IntegrationTests/bin/primary-tests.js @@ -47,9 +47,21 @@ global.globalObject1 = { throw 3.0 }, }, - eval_closure: function(fn) { + eval_closure: function (fn) { return fn(arguments[1]) - } + }, + observable_obj: { + set_called: false, + target: new Proxy({ + nested: {} + }, { + set(target, key, value) { + global.globalObject1.observable_obj.set_called = true; + target[key] = value; + return true; + } + }) + }, }; global.Animal = function (name, age, isCat) { From faa928e3ac5894aefe86ae1ebe56d5a9cc6ad730 Mon Sep 17 00:00:00 2001 From: Yuta Saito Date: Sun, 18 Jul 2021 22:01:25 +0900 Subject: [PATCH 7/7] Add utility assert function for closure crash --- .../TestSuites/Sources/PrimaryTests/main.swift | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/IntegrationTests/TestSuites/Sources/PrimaryTests/main.swift b/IntegrationTests/TestSuites/Sources/PrimaryTests/main.swift index 29052720b..ea12262ef 100644 --- a/IntegrationTests/TestSuites/Sources/PrimaryTests/main.swift +++ b/IntegrationTests/TestSuites/Sources/PrimaryTests/main.swift @@ -186,6 +186,12 @@ try test("Function Call") { let evalClosure = JSObject.global.globalObject1.eval_closure.function! try test("Closure Lifetime") { + func expectCrashByCall(ofClosure c: JSClosureProtocol) throws { + print("======= BEGIN OF EXPECTED FATAL ERROR =====") + _ = try expectThrow(try evalClosure.throws(c)) + print("======= END OF EXPECTED FATAL ERROR =======") + } + do { let c1 = JSClosure { arguments in return arguments[0] @@ -200,9 +206,7 @@ try test("Closure Lifetime") { } c1.release() // Call a released closure - print("======= BEGIN OF EXPECTED FATAL ERROR =====") - _ = try expectThrow(try evalClosure.throws(c1)) - print("======= END OF EXPECTED FATAL ERROR =======") + try expectCrashByCall(ofClosure: c1) } do { @@ -211,9 +215,7 @@ try test("Closure Lifetime") { _ = JSClosure { _ in .undefined } return .undefined } - print("======= BEGIN OF EXPECTED FATAL ERROR =====") - _ = try expectThrow(try evalClosure.throws(c1)) - print("======= END OF EXPECTED FATAL ERROR =======") + try expectCrashByCall(ofClosure: c1) c1.release() } @@ -223,9 +225,7 @@ try test("Closure Lifetime") { } try expectEqual(evalClosure(c1), .boolean(true)) // second call will cause `fatalError` that can be caught as a JavaScript exception - print("======= BEGIN OF EXPECTED FATAL ERROR =====") - _ = try expectThrow(try evalClosure.throws(c1)) - print("======= END OF EXPECTED FATAL ERROR =======") + try expectCrashByCall(ofClosure: c1) // OneshotClosure won't call fatalError even if it's deallocated before `release` } }