Skip to content

Reenable integration tests #180

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

Merged
merged 2 commits into from
Apr 7, 2022
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
1 change: 1 addition & 0 deletions IntegrationTests/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ TestSuites/.build/$(CONFIGURATION)/%.wasm: FORCE
--triple wasm32-unknown-wasi \
--configuration $(CONFIGURATION) \
-Xswiftc -Xclang-linker -Xswiftc -mexec-model=reactor \
-Xlinker --export=main \
$(SWIFT_BUILD_FLAGS)

dist/%.wasm: TestSuites/.build/$(CONFIGURATION)/%.wasm
Expand Down
23 changes: 0 additions & 23 deletions IntegrationTests/TestSuites/Sources/PrimaryTests/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -804,28 +804,5 @@ try test("Hashable Conformance") {
try expectEqual(firstHash, secondHash)
}

try test("Symbols") {
let symbol1 = JSSymbol("abc")
let symbol2 = JSSymbol("abc")
try expectNotEqual(symbol1, symbol2)
try expectEqual(symbol1.name, symbol2.name)
try expectEqual(symbol1.name, "abc")

try expectEqual(JSSymbol.iterator, JSSymbol.iterator)

// let hasInstanceClass = {
// prop: Object.assign(function () {}, {
// [Symbol.hasInstance]() { return true }
// })
// }.prop
let hasInstanceObject = JSObject.global.Object.function!.new()
hasInstanceObject.prop = JSClosure { _ in .undefined }.jsValue
let hasInstanceClass = hasInstanceObject.prop.function!
hasInstanceClass[JSSymbol.hasInstance] = JSClosure { _ in
return .boolean(true)
}.jsValue
try expectEqual(hasInstanceClass[JSSymbol.hasInstance].function!().boolean, true)
try expectEqual(JSObject.global.Object.isInstanceOf(hasInstanceClass), true)
}

Expectation.wait(expectations)
2 changes: 2 additions & 0 deletions IntegrationTests/lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ const startWasiTask = async (wasmPath) => {
swift.setInstance(instance);
// Start the WebAssembly WASI instance!
wasi.start(instance);
instance.exports._initialize();
instance.exports.main();
Copy link
Member

Choose a reason for hiding this comment

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

Why isn’t this called by e.g. wasi.start? Is there a way to make sure existing users will make this change when upgrading?

Copy link
Member Author

Choose a reason for hiding this comment

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

That's because @wasmer/wasi doesn't support reactor. But even though WASI implementation supports it, users need to call WASI.initialize instead: https://nodejs.org/api/wasi.html#wasiinitializeinstance.

These kinds are mutually exclusive;

https://github.com/WebAssembly/WASI/blob/59cbe140561db52fc505555e859de884e0ee7f00/legacy/application-abi.md#current-unstable-abi

And they (command and reactor) are exclusive, so there is no way to upgrade without changing entrypoints

};

module.exports = { startWasiTask };
6 changes: 0 additions & 6 deletions Runtime/src/js-value.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ export enum Kind {
Null = 4,
Undefined = 5,
Function = 6,
Symbol = 7,
}

export const decode = (
Expand Down Expand Up @@ -103,11 +102,6 @@ export const write = (
memory.writeUint32(payload1_ptr, memory.retain(value));
break;
}
case "symbol": {
memory.writeUint32(kind_ptr, exceptionBit | Kind.Symbol);
memory.writeUint32(payload1_ptr, memory.retain(value));
break;
}
default:
throw new Error(`Type "${typeof value}" is not supported yet`);
}
Expand Down
24 changes: 16 additions & 8 deletions Runtime/src/object-heap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,33 @@ export class SwiftRuntimeHeap {
}

retain(value: any) {
const isObject = typeof value == "object";
const entry = this._heapEntryByValue.get(value);
if (entry) {
if (isObject && entry) {
entry.rc++;
return entry.id;
}
const id = this._heapNextKey++;
this._heapValueById.set(id, value);
this._heapEntryByValue.set(value, { id: id, rc: 1 });
if (isObject) {
this._heapEntryByValue.set(value, { id: id, rc: 1 });
}
return id;
}

release(ref: ref) {
const value = this._heapValueById.get(ref);
const entry = this._heapEntryByValue.get(value)!;
entry.rc--;
if (entry.rc != 0) return;

this._heapEntryByValue.delete(value);
this._heapValueById.delete(ref);
const isObject = typeof value == "object";
if (isObject) {
const entry = this._heapEntryByValue.get(value)!;
entry.rc--;
if (entry.rc != 0) return;

this._heapEntryByValue.delete(value);
this._heapValueById.delete(ref);
} else {
this._heapValueById.delete(ref);
}
}

referenceHeap(ref: ref) {
Expand Down
5 changes: 0 additions & 5 deletions Sources/JavaScriptKit/ConvertibleToJSValue.swift
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,6 @@ extension RawJSValue: ConvertibleToJSValue {
return .undefined
case .function:
return .function(JSFunction(id: UInt32(payload1)))
case .symbol:
return .symbol(JSSymbol(id: UInt32(payload1)))
}
}
}
Expand Down Expand Up @@ -240,9 +238,6 @@ extension JSValue {
case let .function(functionRef):
kind = .function
payload1 = JavaScriptPayload1(functionRef.id)
case let .symbol(symbolRef):
kind = .symbol
payload1 = JavaScriptPayload1(symbolRef.id)
}
let rawValue = RawJSValue(kind: kind, payload1: payload1, payload2: payload2)
return body(rawValue)
Expand Down
17 changes: 9 additions & 8 deletions Sources/JavaScriptKit/FundamentalObjects/JSFunction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@ import _CJavaScriptKit
/// ```
///
public class JSFunction: JSObject {

/// Call this function with given `arguments` and binding given `this` as context.
/// - Parameters:
/// - this: The value to be passed as the `this` parameter to this function.
/// - arguments: Arguments to be passed to this function.
/// - Returns: The result of this call.
@discardableResult
public func callAsFunction(this: JSObject? = nil, arguments: [ConvertibleToJSValue]) -> JSValue {
invokeNonThrowingJSFunction(self, arguments: arguments, this: this).jsValue
invokeNonThrowingJSFunction(self, arguments: arguments, this: this)
}

/// A variadic arguments version of `callAsFunction`.
Expand All @@ -40,7 +41,7 @@ public class JSFunction: JSObject {
public func new(arguments: [ConvertibleToJSValue]) -> JSObject {
arguments.withRawJSValues { rawValues in
rawValues.withUnsafeBufferPointer { bufferPointer in
JSObject(id: _call_new(self.id, bufferPointer.baseAddress!, Int32(bufferPointer.count)))
return JSObject(id: _call_new(self.id, bufferPointer.baseAddress!, Int32(bufferPointer.count)))
}
}
}
Expand Down Expand Up @@ -74,7 +75,7 @@ public class JSFunction: JSObject {
fatalError("unavailable")
}

override public class func construct(from value: JSValue) -> Self? {
public override class func construct(from value: JSValue) -> Self? {
return value.function as? Self
}

Expand All @@ -83,18 +84,18 @@ public class JSFunction: JSObject {
}
}

func invokeNonThrowingJSFunction(_ jsFunc: JSFunction, arguments: [ConvertibleToJSValue], this: JSObject?) -> RawJSValue {
private func invokeNonThrowingJSFunction(_ jsFunc: JSFunction, arguments: [ConvertibleToJSValue], this: JSObject?) -> JSValue {
arguments.withRawJSValues { rawValues in
rawValues.withUnsafeBufferPointer { bufferPointer in
rawValues.withUnsafeBufferPointer { bufferPointer -> (JSValue) in
let argv = bufferPointer.baseAddress
let argc = bufferPointer.count
var kindAndFlags = JavaScriptValueKindAndFlags()
var payload1 = JavaScriptPayload1()
var payload2 = JavaScriptPayload2()
if let thisId = this?.id {
_call_function_with_this_no_catch(thisId,
jsFunc.id, argv, Int32(argc),
&kindAndFlags, &payload1, &payload2)
jsFunc.id, argv, Int32(argc),
&kindAndFlags, &payload1, &payload2)
} else {
_call_function_no_catch(
jsFunc.id, argv, Int32(argc),
Expand All @@ -103,7 +104,7 @@ func invokeNonThrowingJSFunction(_ jsFunc: JSFunction, arguments: [ConvertibleTo
}
assert(!kindAndFlags.isException)
let result = RawJSValue(kind: kindAndFlags.kind, payload1: payload1, payload2: payload2)
return result
return result.jsValue()
}
}
}
8 changes: 0 additions & 8 deletions Sources/JavaScriptKit/FundamentalObjects/JSObject.swift
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,6 @@ public class JSObject: Equatable {
set { setJSValue(this: self, index: Int32(index), value: newValue) }
}

/// Access the `symbol` member dynamically through JavaScript and Swift runtime bridge library.
/// - Parameter symbol: The name of this object's member to access.
/// - Returns: The value of the `name` member of this object.
public subscript(_ name: JSSymbol) -> JSValue {
get { getJSValue(this: self, symbol: name) }
set { setJSValue(this: self, symbol: name, value: newValue) }
}

/// A modifier to call methods as throwing methods capturing `this`
///
///
Expand Down
56 changes: 0 additions & 56 deletions Sources/JavaScriptKit/FundamentalObjects/JSSymbol.swift

This file was deleted.

Loading