Skip to content

Commit

Permalink
Implemented Promise. Closes dop251#178.
Browse files Browse the repository at this point in the history
  • Loading branch information
dop251 committed Oct 22, 2021
1 parent 625017e commit dc8c550
Show file tree
Hide file tree
Showing 12 changed files with 797 additions and 55 deletions.
6 changes: 1 addition & 5 deletions builtin_array.go
Original file line number Diff line number Diff line change
Expand Up @@ -1354,11 +1354,7 @@ func (r *Runtime) createArray(val *Object) objectImpl {
o._putProp("from", r.newNativeFunc(r.array_from, nil, "from", nil, 1), true, false, true)
o._putProp("isArray", r.newNativeFunc(r.array_isArray, nil, "isArray", nil, 1), true, false, true)
o._putProp("of", r.newNativeFunc(r.array_of, nil, "of", nil, 0), true, false, true)
o._putSym(SymSpecies, &valueProperty{
getterFunc: r.newNativeFunc(r.returnThis, nil, "get [Symbol.species]", nil, 0),
accessor: true,
configurable: true,
})
r.putSpeciesReturnThis(o)

return o
}
Expand Down
26 changes: 26 additions & 0 deletions builtin_error.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,27 @@
package goja

func (r *Runtime) builtin_Error(args []Value, proto *Object) *Object {
obj := r.newBaseObject(proto, classError)
if len(args) > 0 && args[0] != _undefined {
obj._putProp("message", args[0], true, false, true)
}
return obj.val
}

func (r *Runtime) builtin_AggregateError(args []Value, proto *Object) *Object {
obj := r.newBaseObject(proto, classAggError)
if len(args) > 1 && args[1] != _undefined {
obj._putProp("message", args[1], true, false, true)
}
var errors []Value
if len(args) > 0 {
errors = r.iterableToList(args[0], nil)
}
obj._putProp("errors", r.newArrayValues(errors), true, false, true)

return obj.val
}

func (r *Runtime) createErrorPrototype(name valueString) *Object {
o := r.newBaseObject(r.global.ErrorPrototype, classObject)
o._putProp("message", stringEmpty, true, false, true)
Expand All @@ -17,6 +39,10 @@ func (r *Runtime) initErrors() {
r.global.Error = r.newNativeFuncConstruct(r.builtin_Error, "Error", r.global.ErrorPrototype, 1)
r.addToGlobal("Error", r.global.Error)

r.global.AggregateErrorPrototype = r.createErrorPrototype(stringAggregateError)
r.global.AggregateError = r.newNativeFuncConstructProto(r.builtin_AggregateError, "AggregateError", r.global.AggregateErrorPrototype, r.global.Error, 1)
r.addToGlobal("AggregateError", r.global.AggregateError)

r.global.TypeErrorPrototype = r.createErrorPrototype(stringTypeError)

r.global.TypeError = r.newNativeFuncConstructProto(r.builtin_Error, "TypeError", r.global.TypeErrorPrototype, r.global.Error, 1)
Expand Down
6 changes: 1 addition & 5 deletions builtin_map.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,11 +243,7 @@ func (r *Runtime) createMapProto(val *Object) objectImpl {

func (r *Runtime) createMap(val *Object) objectImpl {
o := r.newNativeConstructOnly(val, r.builtin_newMap, r.global.MapPrototype, "Map", 0)
o._putSym(SymSpecies, &valueProperty{
getterFunc: r.newNativeFunc(r.returnThis, nil, "get [Symbol.species]", nil, 0),
accessor: true,
configurable: true,
})
r.putSpeciesReturnThis(o)

return o
}
Expand Down
Loading

0 comments on commit dc8c550

Please sign in to comment.