Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gardening tests #133

Merged
merged 7 commits into from
Jul 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Example/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 12 additions & 12 deletions Example/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 23 additions & 4 deletions IntegrationTests/TestSuites/Sources/PrimaryTests/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -200,7 +206,7 @@ try test("Closure Lifetime") {
}
c1.release()
// Call a released closure
_ = try expectThrow(try evalClosure.throws(c1))
Copy link
Contributor

@MaxDesiatov MaxDesiatov Jul 18, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should expectThrow contain these prints to avoid repetition?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

expectThrow is not for crash tests, so I added another helper function

try expectCrashByCall(ofClosure: c1)
}

do {
Expand All @@ -209,7 +215,7 @@ try test("Closure Lifetime") {
_ = JSClosure { _ in .undefined }
return .undefined
}
_ = try expectThrow(try evalClosure.throws(c1))
try expectCrashByCall(ofClosure: c1)
c1.release()
}

Expand All @@ -219,7 +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
_ = try expectThrow(try evalClosure.throws(c1))
try expectCrashByCall(ofClosure: c1)
// OneshotClosure won't call fatalError even if it's deallocated before `release`
}
}
Expand Down Expand Up @@ -617,12 +623,25 @@ 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"))

/* 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") {
Expand Down
16 changes: 14 additions & 2 deletions IntegrationTests/bin/primary-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
14 changes: 9 additions & 5 deletions IntegrationTests/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.