@@ -68,7 +68,9 @@ public class JavaScriptEnvironment: ComponentBase, Environment {
6868 private var groups : [ String : ObjectGroup ] = [ : ]
6969
7070 public var constructables = [ String] ( )
71- public let nonConstructables = [ " Math " , " JSON " , " Reflect " , " Symbol " ]
71+
72+ // Builtin objects (ObjectGroups to be precise) that are not constructors.
73+ public let nonConstructors = [ " Math " , " JSON " , " Reflect " ]
7274
7375 public init ( additionalBuiltins: [ String : Type ] , additionalObjectGroups: [ ObjectGroup ] ) {
7476 super. init ( name: " JavaScriptEnvironment " )
@@ -183,13 +185,15 @@ public class JavaScriptEnvironment: ComponentBase, Environment {
183185 for group in groups. keys where !group. contains ( " Constructor " ) {
184186 assert ( builtins. contains ( group) , " We cannot call the constructor for the given group \( group) " )
185187
186- if !nonConstructables. contains ( group) {
187- assert ( type ( ofBuiltin: group) . constructorSignature != nil , " We don't have a constructor signature for \( group) " )
188- // These are basically the groups that need to be constructable i.e. callable with the new keyword.
188+ if !nonConstructors. contains ( group) {
189+ // These are the groups that are constructable i.e. for which a builtin exists with the name of the group
190+ // that can be called as function or constructor and returns an object of that group.
191+ assert ( type ( ofBuiltin: group) . signature != nil , " We don't have a constructor signature for \( group) " )
192+ assert ( type ( ofBuiltin: group) . signature!. outputType. group == group, " The constructor for \( group) returns an invalid type " )
189193 constructables. append ( group)
190194 }
191195 }
192-
196+
193197 customPropertyNames = [ " a " , " b " , " c " , " d " , " e " ]
194198 customMethodNames = [ " m " , " n " , " o " , " p " ]
195199 methodNames. formUnion ( customMethodNames)
@@ -346,7 +350,7 @@ public extension Type {
346350 }
347351
348352 /// Type of the JavaScript Object constructor builtin.
349- static let jsObjectConstructor = . functionAndConstructor( [ . anything... ] => . object( ) ) + . object( ofGroup: " ObjectConstructor " , withProperties: [ " prototype " ] , withMethods: [ " assign " , " fromEntries " , " getOwnPropertyDescriptor " , " getOwnPropertyDescriptors " , " getOwnPropertyNames " , " getOwnPropertySymbols " , " is " , " preventExtensions " , " seal " , " create " , " defineProperties " , " defineProperty " , " freeze " , " getPrototypeOf " , " setPrototypeOf " , " isExtensible " , " isFrozen " , " isSealed " , " keys " , " entries " , " values " ] )
353+ static let jsObjectConstructor = . functionAndConstructor( [ . anything... ] => . object( ofGroup : " Object " ) ) + . object( ofGroup: " ObjectConstructor " , withProperties: [ " prototype " ] , withMethods: [ " assign " , " fromEntries " , " getOwnPropertyDescriptor " , " getOwnPropertyDescriptors " , " getOwnPropertyNames " , " getOwnPropertySymbols " , " is " , " preventExtensions " , " seal " , " create " , " defineProperties " , " defineProperty " , " freeze " , " getPrototypeOf " , " setPrototypeOf " , " isExtensible " , " isFrozen " , " isSealed " , " keys " , " entries " , " values " ] )
350354
351355 /// Type of the JavaScript Array constructor builtin.
352356 static let jsArrayConstructor = . functionAndConstructor( [ . integer] => . jsArray) + . object( ofGroup: " ArrayConstructor " , withProperties: [ " prototype " ] , withMethods: [ " from " , " of " , " isArray " ] )
0 commit comments