@@ -10,7 +10,6 @@ public enum JSValue: Equatable {
10
10
case null
11
11
case undefined
12
12
case function( JSFunction )
13
- case symbol( JSSymbol )
14
13
15
14
/// Returns the `Bool` value of this JS value if its type is boolean.
16
15
/// If not, returns `nil`.
@@ -68,13 +67,6 @@ public enum JSValue: Equatable {
68
67
}
69
68
}
70
69
71
- public var symbol : JSSymbol ? {
72
- switch self {
73
- case let . symbol( symbol) : return symbol
74
- default : return nil
75
- }
76
- }
77
-
78
70
/// Returns the `true` if this JS value is null.
79
71
/// If not, returns `false`.
80
72
public var isNull : Bool {
@@ -88,38 +80,39 @@ public enum JSValue: Equatable {
88
80
}
89
81
}
90
82
91
- public extension JSValue {
83
+ extension JSValue {
92
84
/// An unsafe convenience method of `JSObject.subscript(_ name: String) -> ((ConvertibleToJSValue...) -> JSValue)?`
93
85
/// - Precondition: `self` must be a JavaScript Object and specified member should be a callable object.
94
- subscript( dynamicMember name: String ) -> ( ( ConvertibleToJSValue . . . ) -> JSValue ) {
86
+ public subscript( dynamicMember name: String ) -> ( ( ConvertibleToJSValue . . . ) -> JSValue ) {
95
87
object![ dynamicMember: name] !
96
88
}
97
89
98
90
/// An unsafe convenience method of `JSObject.subscript(_ index: Int) -> JSValue`
99
91
/// - Precondition: `self` must be a JavaScript Object.
100
- subscript( dynamicMember name: String ) -> JSValue {
92
+ public subscript( dynamicMember name: String ) -> JSValue {
101
93
get { self . object![ name] }
102
94
set { self . object![ name] = newValue }
103
95
}
104
96
105
97
/// An unsafe convenience method of `JSObject.subscript(_ index: Int) -> JSValue`
106
98
/// - Precondition: `self` must be a JavaScript Object.
107
- subscript( _ index: Int ) -> JSValue {
99
+ public subscript( _ index: Int ) -> JSValue {
108
100
get { object![ index] }
109
101
set { object![ index] = newValue }
110
102
}
111
103
}
112
104
113
105
extension JSValue : Swift . Error { }
114
106
115
- public extension JSValue {
116
- func fromJSValue< Type> ( ) -> Type ? where Type: ConstructibleFromJSValue {
107
+ extension JSValue {
108
+ public func fromJSValue< Type> ( ) -> Type ? where Type: ConstructibleFromJSValue {
117
109
return Type . construct ( from: self )
118
110
}
119
111
}
120
112
121
- public extension JSValue {
122
- static func string( _ value: String ) -> JSValue {
113
+ extension JSValue {
114
+
115
+ public static func string( _ value: String ) -> JSValue {
123
116
. string( JSString ( value) )
124
117
}
125
118
@@ -148,12 +141,12 @@ public extension JSValue {
148
141
/// eventListenter.release()
149
142
/// ```
150
143
@available ( * , deprecated, message: " Please create JSClosure directly and manage its lifetime manually. " )
151
- static func function( _ body: @escaping ( [ JSValue ] ) -> JSValue ) -> JSValue {
144
+ public static func function( _ body: @escaping ( [ JSValue ] ) -> JSValue ) -> JSValue {
152
145
. object( JSClosure ( body) )
153
146
}
154
147
155
148
@available ( * , deprecated, renamed: " object " , message: " JSClosure is no longer a subclass of JSFunction. Use .object(closure) instead. " )
156
- static func function( _ closure: JSClosure ) -> JSValue {
149
+ public static func function( _ closure: JSClosure ) -> JSValue {
157
150
. object( closure)
158
151
}
159
152
}
@@ -177,7 +170,7 @@ extension JSValue: ExpressibleByFloatLiteral {
177
170
}
178
171
179
172
extension JSValue : ExpressibleByNilLiteral {
180
- public init ( nilLiteral _ : ( ) ) {
173
+ public init ( nilLiteral: ( ) ) {
181
174
self = . null
182
175
}
183
176
}
@@ -212,28 +205,14 @@ public func setJSValue(this: JSObject, index: Int32, value: JSValue) {
212
205
}
213
206
}
214
207
215
- public func getJSValue( this: JSObject , symbol: JSSymbol ) -> JSValue {
216
- var rawValue = RawJSValue ( )
217
- _get_prop ( this. id, symbol. id,
218
- & rawValue. kind,
219
- & rawValue. payload1, & rawValue. payload2)
220
- return rawValue. jsValue
221
- }
222
-
223
- public func setJSValue( this: JSObject , symbol: JSSymbol , value: JSValue ) {
224
- value. withRawJSValue { rawValue in
225
- _set_prop ( this. id, symbol. id, rawValue. kind, rawValue. payload1, rawValue. payload2)
226
- }
227
- }
228
-
229
- public extension JSValue {
230
- /// Return `true` if this value is an instance of the passed `constructor` function.
231
- /// Returns `false` for everything except objects and functions.
232
- /// - Parameter constructor: The constructor function to check.
233
- /// - Returns: The result of `instanceof` in the JavaScript environment.
234
- func isInstanceOf( _ constructor: JSFunction ) -> Bool {
208
+ extension JSValue {
209
+ /// Return `true` if this value is an instance of the passed `constructor` function.
210
+ /// Returns `false` for everything except objects and functions.
211
+ /// - Parameter constructor: The constructor function to check.
212
+ /// - Returns: The result of `instanceof` in the JavaScript environment.
213
+ public func isInstanceOf( _ constructor: JSFunction ) -> Bool {
235
214
switch self {
236
- case . boolean, . string, . number, . null, . undefined, . symbol :
215
+ case . boolean, . string, . number, . null, . undefined:
237
216
return false
238
217
case let . object( ref) :
239
218
return ref. isInstanceOf ( constructor)
@@ -248,12 +227,11 @@ extension JSValue: CustomStringConvertible {
248
227
switch self {
249
228
case let . boolean( boolean) :
250
229
return boolean. description
251
- case let . string( string) :
230
+ case . string( let string) :
252
231
return string. description
253
- case let . number( number) :
232
+ case . number( let number) :
254
233
return number. description
255
- case let . object( object) , let . function( object as JSObject ) ,
256
- . symbol( let object as JSObject ) :
234
+ case . object( let object) , . function( let object as JSObject ) :
257
235
return object. toString!( ) . fromJSValue ( ) !
258
236
case . null:
259
237
return " null "
0 commit comments