Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BAAS-24621: Implement object templates #103

Merged
merged 13 commits into from
Oct 20, 2023
24 changes: 12 additions & 12 deletions added_values.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ func (i valueNumber) ToBoolean() bool {
}

func (i valueNumber) ToObject(r *Runtime) *Object {
return r.newPrimitiveObject(i, r.global.NumberPrototype, classNumber)
return r.newPrimitiveObject(i, r.getNumberPrototype(), classNumber)
Calvinnix marked this conversation as resolved.
Show resolved Hide resolved
}

func (i valueNumber) ToNumber() Value {
Expand Down Expand Up @@ -158,7 +158,7 @@ func (i valueNumber) Equals(other Value) bool {
return i.ToInt() == o.ToInt()
}
if o, ok := other.(*Object); ok {
return i.Equals(o.self.toPrimitiveNumber())
return i.Equals(o.toPrimitiveNumber())
Calvinnix marked this conversation as resolved.
Show resolved Hide resolved
}
return false
}
Expand Down Expand Up @@ -194,7 +194,7 @@ func (i valueNumber) assertString() (valueString, bool) {
}

func (i valueNumber) baseObject(r *Runtime) *Object {
return r.global.NumberPrototype
return r.getNumberPrototype()
}

func (i valueNumber) Export() interface{} {
Expand Down Expand Up @@ -256,7 +256,7 @@ func (i valueUInt32) ToBoolean() bool {
}

func (i valueUInt32) ToObject(r *Runtime) *Object {
return r.newPrimitiveObject(i, r.global.NumberPrototype, classNumber)
return r.newPrimitiveObject(i, r.getNumberPrototype(), classNumber)
}

func (i valueUInt32) ToNumber() Value {
Expand Down Expand Up @@ -284,7 +284,7 @@ func (i valueUInt32) Equals(other Value) bool {
return int(i) == o.ToInt()
}
if o, ok := other.(*Object); ok {
return i.Equals(o.self.toPrimitiveNumber())
return i.Equals(o.toPrimitiveNumber())
}
return false
}
Expand Down Expand Up @@ -324,7 +324,7 @@ func (i valueUInt32) assertString() (valueString, bool) {
}

func (i valueUInt32) baseObject(r *Runtime) *Object {
return r.global.NumberPrototype
return r.getNumberPrototype()
}

func (i valueUInt32) Export() interface{} {
Expand Down Expand Up @@ -389,7 +389,7 @@ func (i valueInt32) ToBoolean() bool {
}

func (i valueInt32) ToObject(r *Runtime) *Object {
return r.newPrimitiveObject(i, r.global.NumberPrototype, classNumber)
return r.newPrimitiveObject(i, r.getNumberPrototype(), classNumber)
}

func (i valueInt32) ToNumber() Value {
Expand Down Expand Up @@ -417,7 +417,7 @@ func (i valueInt32) Equals(other Value) bool {
return int(i) == o.ToInt()
}
if o, ok := other.(*Object); ok {
return i.Equals(o.self.toPrimitiveNumber())
return i.Equals(o.toPrimitiveNumber())
}
return false
}
Expand Down Expand Up @@ -453,7 +453,7 @@ func (i valueInt32) assertString() (valueString, bool) {
}

func (i valueInt32) baseObject(r *Runtime) *Object {
return r.global.NumberPrototype
return r.getNumberPrototype()
}

func (i valueInt32) Export() interface{} {
Expand Down Expand Up @@ -516,7 +516,7 @@ func (i valueInt64) ToBoolean() bool {
}

func (i valueInt64) ToObject(r *Runtime) *Object {
return r.newPrimitiveObject(i, r.global.NumberPrototype, classNumber)
return r.newPrimitiveObject(i, r.getNumberPrototype(), classNumber)
}

func (i valueInt64) ToNumber() Value {
Expand Down Expand Up @@ -544,7 +544,7 @@ func (i valueInt64) Equals(other Value) bool {
return int(i) == o.ToInt()
}
if o, ok := other.(*Object); ok {
return i.Equals(o.self.toPrimitiveNumber())
return i.Equals(o.toPrimitiveNumber())
}
return false
}
Expand Down Expand Up @@ -582,7 +582,7 @@ func (i valueInt64) hash(*maphash.Hash) uint64 {
}

func (i valueInt64) baseObject(r *Runtime) *Object {
return r.global.NumberPrototype
return r.getNumberPrototype()
}

func (i valueInt64) Export() interface{} {
Expand Down
16 changes: 14 additions & 2 deletions array.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
ai.val = o
ai.extensible = true
o.self = ai
arahmanan marked this conversation as resolved.
Show resolved Hide resolved
ai.prototype = r.global.ArrayIteratorPrototype
ai.prototype = r.getArrayIteratorPrototype()
ai.init()

return o
Expand Down Expand Up @@ -333,6 +333,18 @@
return a.baseObject.hasOwnPropertyStr(idx.string())
}

func (a *arrayObject) hasPropertyIdx(idx valueInt) bool {
if a.hasOwnPropertyIdx(idx) {
return true
}

if a.prototype != nil {
return a.prototype.self.hasPropertyIdx(idx)
}

return false
}

func (a *arrayObject) expand(idx uint32) bool {
targetLen := idx + 1
if targetLen > uint32(len(a.values)) {
Expand Down Expand Up @@ -510,7 +522,7 @@

func (a *arrayObject) exportToArrayOrSlice(dst reflect.Value, typ reflect.Type, ctx *objectExportCtx) error {
r := a.val.runtime
if iter := a.getSym(SymIterator, nil); iter == r.global.arrayValues || iter == nil {
if iter := a.getSym(SymIterator, nil); iter == r.getArrayValues() || iter == nil {
l := toIntStrict(int64(a.length))
if typ.Kind() == reflect.Array {
if dst.Len() != l {
Expand Down Expand Up @@ -547,7 +559,7 @@
}

func toIdx(v valueInt) uint32 {
if v >= 0 && v < math.MaxUint32 {

Check failure on line 562 in array.go

View workflow job for this annotation

GitHub Actions / test (1.16.x, ubuntu-latest, 386)

constant 4294967295 overflows valueInt
return uint32(v)
}
return math.MaxUint32
Expand Down
14 changes: 13 additions & 1 deletion array_sparse.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,18 @@ func (a *sparseArrayObject) hasOwnPropertyIdx(idx valueInt) bool {
return a.baseObject.hasOwnPropertyStr(idx.string())
}

func (a *sparseArrayObject) hasPropertyIdx(idx valueInt) bool {
if a.hasOwnPropertyIdx(idx) {
return true
}

if a.prototype != nil {
return a.prototype.self.hasPropertyIdx(idx)
}

return false
}

func (a *sparseArrayObject) expand(idx uint32) bool {
if l := len(a.items); l >= 1024 {
if ii := a.items[l-1].idx; ii > idx {
Expand Down Expand Up @@ -458,7 +470,7 @@ func (a *sparseArrayObject) exportType() reflect.Type {

func (a *sparseArrayObject) exportToArrayOrSlice(dst reflect.Value, typ reflect.Type, ctx *objectExportCtx) error {
r := a.val.runtime
arahmanan marked this conversation as resolved.
Show resolved Hide resolved
if iter := a.getSym(SymIterator, nil); iter == r.global.arrayValues || iter == nil {
if iter := a.getSym(SymIterator, nil); iter == r.getArrayValues() || iter == nil {
l := toIntStrict(int64(a.length))
if typ.Kind() == reflect.Array {
if dst.Len() != l {
Expand Down
Loading
Loading