File tree 4 files changed +47
-10
lines changed
test/JavaScriptKitExec/Sources/JavaScriptKitExec
4 files changed +47
-10
lines changed Original file line number Diff line number Diff line change @@ -21,6 +21,8 @@ public enum JSValue: Equatable {
21
21
case string( String )
22
22
case number( Int32 )
23
23
case object( JSObjectRef )
24
+ case null
25
+ case undefined
24
26
}
25
27
26
28
protocol JSValueConvertible {
@@ -60,6 +62,10 @@ extension RawJSValue: JSValueConvertible {
60
62
return . string( string)
61
63
case JavaScriptValueKind_Object:
62
64
return . object( JSObjectRef ( id: payload1) )
65
+ case JavaScriptValueKind_Null:
66
+ return . null
67
+ case JavaScriptValueKind_Undefined:
68
+ return . undefined
63
69
default :
64
70
fatalError ( " unreachable " )
65
71
}
@@ -91,6 +97,14 @@ extension JSValue {
91
97
kind = JavaScriptValueKind_Object
92
98
payload1 = ref. id
93
99
payload2 = 0
100
+ case . null:
101
+ kind = JavaScriptValueKind_Null
102
+ payload1 = 0
103
+ payload2 = 0
104
+ case . undefined:
105
+ kind = JavaScriptValueKind_Undefined
106
+ payload1 = 0
107
+ payload2 = 0
94
108
}
95
109
let rawValue = RawJSValue ( kind: kind, payload1: payload1, payload2: payload2)
96
110
return body ( rawValue)
Original file line number Diff line number Diff line change 6
6
typedef unsigned int JavaScriptValueId ;
7
7
8
8
typedef enum {
9
- JavaScriptValueKind_Invalid = -1 ,
10
- JavaScriptValueKind_Boolean = 0 ,
11
- JavaScriptValueKind_String = 1 ,
12
- JavaScriptValueKind_Number = 2 ,
13
- JavaScriptValueKind_Object = 3 ,
14
- JavaScriptValueKind_Null = 4 ,
15
- JavaScriptValueKind_Function = 5 ,
9
+ JavaScriptValueKind_Invalid = -1 ,
10
+ JavaScriptValueKind_Boolean = 0 ,
11
+ JavaScriptValueKind_String = 1 ,
12
+ JavaScriptValueKind_Number = 2 ,
13
+ JavaScriptValueKind_Object = 3 ,
14
+ JavaScriptValueKind_Null = 4 ,
15
+ JavaScriptValueKind_Undefined = 5 ,
16
+ JavaScriptValueKind_Function = 6 ,
16
17
} JavaScriptValueKind ;
17
18
18
19
typedef unsigned JavaScriptPayload ;
Original file line number Diff line number Diff line change @@ -16,8 +16,8 @@ enum JavaScriptValueKind {
16
16
String = 1 ,
17
17
Number = 2 ,
18
18
Object = 3 ,
19
- Array = 4 ,
20
- Null = 5 ,
19
+ Null = 4 ,
20
+ Undefined = 5 ,
21
21
Function = 6 ,
22
22
}
23
23
@@ -101,12 +101,25 @@ export class SwiftRuntime {
101
101
case JavaScriptValueKind . Object : {
102
102
return this . _heapValues [ payload1 ]
103
103
}
104
+ case JavaScriptValueKind . Null : {
105
+ return null
106
+ }
107
+ case JavaScriptValueKind . Undefined : {
108
+ return undefined
109
+ }
104
110
default :
105
111
throw new Error ( `Type kind "${ kind } " is not supported` )
106
112
}
107
113
}
108
114
109
115
const encodeValue = ( value : any ) => {
116
+ if ( value === null ) {
117
+ return {
118
+ kind : JavaScriptValueKind . Null ,
119
+ payload1 : 0 ,
120
+ payload2 : 0 ,
121
+ }
122
+ }
110
123
switch ( typeof value ) {
111
124
case "boolean" : {
112
125
return {
@@ -129,6 +142,13 @@ export class SwiftRuntime {
129
142
payload2 : value . length ,
130
143
}
131
144
}
145
+ case "undefined" : {
146
+ return {
147
+ kind : JavaScriptValueKind . Undefined ,
148
+ payload1 : 0 ,
149
+ payload2 : 0 ,
150
+ }
151
+ }
132
152
case "object" : {
133
153
return {
134
154
kind : JavaScriptValueKind . Object ,
Original file line number Diff line number Diff line change @@ -9,12 +9,14 @@ Literal_Conversion: do {
9
9
. number( 0 ) ,
10
10
. number( . max) ,
11
11
. number( . min) ,
12
+ . null,
13
+ . undefined,
12
14
]
13
15
for (index, input) in inputs. enumerated ( ) {
14
16
let prop = " prop_ \( index) "
15
17
setJSValue ( this: global, name: prop, value: input)
16
18
let got = getJSValue ( this: global, name: prop)
17
- try expectEqual ( input , got )
19
+ try expectEqual ( got , input )
18
20
}
19
21
} catch {
20
22
print ( error)
You can’t perform that action at this time.
0 commit comments