Skip to content

Commit 54d4a47

Browse files
Merge pull request #180 from swiftwasm/katei/reenable-test
Reenable integration tests
2 parents 95d0c4c + d7ed468 commit 54d4a47

File tree

11 files changed

+50
-163
lines changed

11 files changed

+50
-163
lines changed

IntegrationTests/Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ TestSuites/.build/$(CONFIGURATION)/%.wasm: FORCE
88
--triple wasm32-unknown-wasi \
99
--configuration $(CONFIGURATION) \
1010
-Xswiftc -Xclang-linker -Xswiftc -mexec-model=reactor \
11+
-Xlinker --export=main \
1112
$(SWIFT_BUILD_FLAGS)
1213

1314
dist/%.wasm: TestSuites/.build/$(CONFIGURATION)/%.wasm

IntegrationTests/TestSuites/Sources/PrimaryTests/main.swift

-23
Original file line numberDiff line numberDiff line change
@@ -804,28 +804,5 @@ try test("Hashable Conformance") {
804804
try expectEqual(firstHash, secondHash)
805805
}
806806

807-
try test("Symbols") {
808-
let symbol1 = JSSymbol("abc")
809-
let symbol2 = JSSymbol("abc")
810-
try expectNotEqual(symbol1, symbol2)
811-
try expectEqual(symbol1.name, symbol2.name)
812-
try expectEqual(symbol1.name, "abc")
813-
814-
try expectEqual(JSSymbol.iterator, JSSymbol.iterator)
815-
816-
// let hasInstanceClass = {
817-
// prop: Object.assign(function () {}, {
818-
// [Symbol.hasInstance]() { return true }
819-
// })
820-
// }.prop
821-
let hasInstanceObject = JSObject.global.Object.function!.new()
822-
hasInstanceObject.prop = JSClosure { _ in .undefined }.jsValue
823-
let hasInstanceClass = hasInstanceObject.prop.function!
824-
hasInstanceClass[JSSymbol.hasInstance] = JSClosure { _ in
825-
return .boolean(true)
826-
}.jsValue
827-
try expectEqual(hasInstanceClass[JSSymbol.hasInstance].function!().boolean, true)
828-
try expectEqual(JSObject.global.Object.isInstanceOf(hasInstanceClass), true)
829-
}
830807

831808
Expectation.wait(expectations)

IntegrationTests/lib.js

+2
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ const startWasiTask = async (wasmPath) => {
4545
swift.setInstance(instance);
4646
// Start the WebAssembly WASI instance!
4747
wasi.start(instance);
48+
instance.exports._initialize();
49+
instance.exports.main();
4850
};
4951

5052
module.exports = { startWasiTask };

Runtime/src/js-value.ts

-6
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ export enum Kind {
1010
Null = 4,
1111
Undefined = 5,
1212
Function = 6,
13-
Symbol = 7,
1413
}
1514

1615
export const decode = (
@@ -103,11 +102,6 @@ export const write = (
103102
memory.writeUint32(payload1_ptr, memory.retain(value));
104103
break;
105104
}
106-
case "symbol": {
107-
memory.writeUint32(kind_ptr, exceptionBit | Kind.Symbol);
108-
memory.writeUint32(payload1_ptr, memory.retain(value));
109-
break;
110-
}
111105
default:
112106
throw new Error(`Type "${typeof value}" is not supported yet`);
113107
}

Runtime/src/object-heap.ts

+16-8
Original file line numberDiff line numberDiff line change
@@ -22,25 +22,33 @@ export class SwiftRuntimeHeap {
2222
}
2323

2424
retain(value: any) {
25+
const isObject = typeof value == "object";
2526
const entry = this._heapEntryByValue.get(value);
26-
if (entry) {
27+
if (isObject && entry) {
2728
entry.rc++;
2829
return entry.id;
2930
}
3031
const id = this._heapNextKey++;
3132
this._heapValueById.set(id, value);
32-
this._heapEntryByValue.set(value, { id: id, rc: 1 });
33+
if (isObject) {
34+
this._heapEntryByValue.set(value, { id: id, rc: 1 });
35+
}
3336
return id;
3437
}
3538

3639
release(ref: ref) {
3740
const value = this._heapValueById.get(ref);
38-
const entry = this._heapEntryByValue.get(value)!;
39-
entry.rc--;
40-
if (entry.rc != 0) return;
41-
42-
this._heapEntryByValue.delete(value);
43-
this._heapValueById.delete(ref);
41+
const isObject = typeof value == "object";
42+
if (isObject) {
43+
const entry = this._heapEntryByValue.get(value)!;
44+
entry.rc--;
45+
if (entry.rc != 0) return;
46+
47+
this._heapEntryByValue.delete(value);
48+
this._heapValueById.delete(ref);
49+
} else {
50+
this._heapValueById.delete(ref);
51+
}
4452
}
4553

4654
referenceHeap(ref: ref) {

Sources/JavaScriptKit/ConvertibleToJSValue.swift

-5
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,6 @@ extension RawJSValue: ConvertibleToJSValue {
207207
return .undefined
208208
case .function:
209209
return .function(JSFunction(id: UInt32(payload1)))
210-
case .symbol:
211-
return .symbol(JSSymbol(id: UInt32(payload1)))
212210
}
213211
}
214212
}
@@ -240,9 +238,6 @@ extension JSValue {
240238
case let .function(functionRef):
241239
kind = .function
242240
payload1 = JavaScriptPayload1(functionRef.id)
243-
case let .symbol(symbolRef):
244-
kind = .symbol
245-
payload1 = JavaScriptPayload1(symbolRef.id)
246241
}
247242
let rawValue = RawJSValue(kind: kind, payload1: payload1, payload2: payload2)
248243
return body(rawValue)

Sources/JavaScriptKit/FundamentalObjects/JSFunction.swift

+9-8
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,15 @@ import _CJavaScriptKit
1111
/// ```
1212
///
1313
public class JSFunction: JSObject {
14+
1415
/// Call this function with given `arguments` and binding given `this` as context.
1516
/// - Parameters:
1617
/// - this: The value to be passed as the `this` parameter to this function.
1718
/// - arguments: Arguments to be passed to this function.
1819
/// - Returns: The result of this call.
1920
@discardableResult
2021
public func callAsFunction(this: JSObject? = nil, arguments: [ConvertibleToJSValue]) -> JSValue {
21-
invokeNonThrowingJSFunction(self, arguments: arguments, this: this).jsValue
22+
invokeNonThrowingJSFunction(self, arguments: arguments, this: this)
2223
}
2324

2425
/// A variadic arguments version of `callAsFunction`.
@@ -40,7 +41,7 @@ public class JSFunction: JSObject {
4041
public func new(arguments: [ConvertibleToJSValue]) -> JSObject {
4142
arguments.withRawJSValues { rawValues in
4243
rawValues.withUnsafeBufferPointer { bufferPointer in
43-
JSObject(id: _call_new(self.id, bufferPointer.baseAddress!, Int32(bufferPointer.count)))
44+
return JSObject(id: _call_new(self.id, bufferPointer.baseAddress!, Int32(bufferPointer.count)))
4445
}
4546
}
4647
}
@@ -74,7 +75,7 @@ public class JSFunction: JSObject {
7475
fatalError("unavailable")
7576
}
7677

77-
override public class func construct(from value: JSValue) -> Self? {
78+
public override class func construct(from value: JSValue) -> Self? {
7879
return value.function as? Self
7980
}
8081

@@ -83,18 +84,18 @@ public class JSFunction: JSObject {
8384
}
8485
}
8586

86-
func invokeNonThrowingJSFunction(_ jsFunc: JSFunction, arguments: [ConvertibleToJSValue], this: JSObject?) -> RawJSValue {
87+
private func invokeNonThrowingJSFunction(_ jsFunc: JSFunction, arguments: [ConvertibleToJSValue], this: JSObject?) -> JSValue {
8788
arguments.withRawJSValues { rawValues in
88-
rawValues.withUnsafeBufferPointer { bufferPointer in
89+
rawValues.withUnsafeBufferPointer { bufferPointer -> (JSValue) in
8990
let argv = bufferPointer.baseAddress
9091
let argc = bufferPointer.count
9192
var kindAndFlags = JavaScriptValueKindAndFlags()
9293
var payload1 = JavaScriptPayload1()
9394
var payload2 = JavaScriptPayload2()
9495
if let thisId = this?.id {
9596
_call_function_with_this_no_catch(thisId,
96-
jsFunc.id, argv, Int32(argc),
97-
&kindAndFlags, &payload1, &payload2)
97+
jsFunc.id, argv, Int32(argc),
98+
&kindAndFlags, &payload1, &payload2)
9899
} else {
99100
_call_function_no_catch(
100101
jsFunc.id, argv, Int32(argc),
@@ -103,7 +104,7 @@ func invokeNonThrowingJSFunction(_ jsFunc: JSFunction, arguments: [ConvertibleTo
103104
}
104105
assert(!kindAndFlags.isException)
105106
let result = RawJSValue(kind: kindAndFlags.kind, payload1: payload1, payload2: payload2)
106-
return result
107+
return result.jsValue()
107108
}
108109
}
109110
}

Sources/JavaScriptKit/FundamentalObjects/JSObject.swift

-8
Original file line numberDiff line numberDiff line change
@@ -95,14 +95,6 @@ public class JSObject: Equatable {
9595
set { setJSValue(this: self, index: Int32(index), value: newValue) }
9696
}
9797

98-
/// Access the `symbol` member dynamically through JavaScript and Swift runtime bridge library.
99-
/// - Parameter symbol: The name of this object's member to access.
100-
/// - Returns: The value of the `name` member of this object.
101-
public subscript(_ name: JSSymbol) -> JSValue {
102-
get { getJSValue(this: self, symbol: name) }
103-
set { setJSValue(this: self, symbol: name, value: newValue) }
104-
}
105-
10698
/// A modifier to call methods as throwing methods capturing `this`
10799
///
108100
///

Sources/JavaScriptKit/FundamentalObjects/JSSymbol.swift

-56
This file was deleted.

0 commit comments

Comments
 (0)