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-19768: update goja to latest March 2023 (part 2) #79

Merged
merged 16 commits into from
Mar 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ jobs:
- name: Run go vet
run: go vet ./...
- name: Run staticcheck
uses: dominikh/staticcheck-action@v1.0.0
uses: dominikh/staticcheck-action@v1.1.0
with:
version: "2022.1"
install-go: false
cache-key: ${{ matrix.go-version }}
if: ${{ matrix.go-version == '1.x' }}
Expand Down
2 changes: 1 addition & 1 deletion .tc39_test262_checkout.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/sh
# this is just the commit it was last tested with
sha=e87b0048c402479df1d9cb391fb86620cf3200fd
sha=926b0960d737b9f1dfd0ec0c1dfd95d836016d33

mkdir -p testdata/test262
cd testdata/test262
Expand Down
28 changes: 14 additions & 14 deletions array.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,6 @@ func (a *arrayObject) setLengthInt(l uint32, throw bool) bool {
}

func (a *arrayObject) setLength(v uint32, throw bool) bool {
if v == a.length {
return true
}
if !a.lengthProp.writable {
a.val.runtime.typeErrorResult(throw, "length is not writable")
return false
Expand Down Expand Up @@ -182,27 +179,27 @@ func (a *arrayObject) getOwnPropIdx(idx valueInt) Value {
return a.baseObject.getOwnPropStr(idx.string())
}

func (a *arrayObject) sortLen() int64 {
return int64(len(a.values))
func (a *arrayObject) sortLen() int {
return len(a.values)
}

func (a *arrayObject) sortGet(i int64) Value {
func (a *arrayObject) sortGet(i int) Value {
v := a.values[i]
if p, ok := v.(*valueProperty); ok {
v = p.get(a.val)
}
return v
}

func (a *arrayObject) swap(i, j int64) {
func (a *arrayObject) swap(i int, j int) {
a.values[i], a.values[j] = a.values[j], a.values[i]
}

func (a *arrayObject) getStr(name unistring.String, receiver Value) Value {
return a.getStrWithOwnProp(a.getOwnPropStr(name), name, receiver)
}

func (a *arrayObject) getLengthProp() Value {
func (a *arrayObject) getLengthProp() *valueProperty {
a.lengthProp.value = intToValue(int64(a.length))
return &a.lengthProp
}
Expand Down Expand Up @@ -383,7 +380,10 @@ func (r *Runtime) defineArrayLength(prop *valueProperty, descr PropertyDescripto
}

if descr.Value != nil {
ret = setter(newLen, false)
oldLen := uint32(prop.value.ToInteger())
if oldLen != newLen {
ret = setter(newLen, false)
}
} else {
ret = true
}
Expand Down Expand Up @@ -438,7 +438,7 @@ func (a *arrayObject) defineOwnPropertyStr(name unistring.String, descr Property
return a._defineIdxProperty(idx, descr, throw)
}
if name == "length" {
return a.val.runtime.defineArrayLength(&a.lengthProp, descr, a.setLength, throw)
return a.val.runtime.defineArrayLength(a.getLengthProp(), descr, a.setLength, throw)
}
return a.baseObject.defineOwnPropertyStr(name, descr, throw)
}
Expand Down Expand Up @@ -512,12 +512,12 @@ func (a *arrayObject) exportToArrayOrSlice(dst reflect.Value, typ reflect.Type,
r := a.val.runtime
if iter := a.getSym(SymIterator, nil); iter == r.global.arrayValues || iter == nil {
l := toIntStrict(int64(a.length))
if dst.Len() != l {
if typ.Kind() == reflect.Array {
if typ.Kind() == reflect.Array {
if dst.Len() != l {
return fmt.Errorf("cannot convert an Array into an array, lengths mismatch (have %d, need %d)", l, dst.Len())
} else {
dst.Set(reflect.MakeSlice(typ, l, l))
}
} else {
dst.Set(reflect.MakeSlice(typ, l, l))
}
ctx.putTyped(a.val, typ, dst.Interface())
for i := 0; i < l; i++ {
Expand Down
19 changes: 8 additions & 11 deletions array_sparse.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,6 @@ func (a *sparseArrayObject) setLengthInt(l uint32, throw bool) bool {
}

func (a *sparseArrayObject) setLength(v uint32, throw bool) bool {
if v == a.length {
return true
}
if !a.lengthProp.writable {
a.val.runtime.typeErrorResult(throw, "length is not writable")
return false
Expand Down Expand Up @@ -120,7 +117,7 @@ func (a *sparseArrayObject) getIdx(idx valueInt, receiver Value) Value {
return prop
}

func (a *sparseArrayObject) getLengthProp() Value {
func (a *sparseArrayObject) getLengthProp() *valueProperty {
a.lengthProp.value = intToValue(int64(a.length))
return &a.lengthProp
}
Expand Down Expand Up @@ -369,7 +366,7 @@ func (a *sparseArrayObject) defineOwnPropertyStr(name unistring.String, descr Pr
return a._defineIdxProperty(idx, descr, throw)
}
if name == "length" {
return a.val.runtime.defineArrayLength(&a.lengthProp, descr, a.setLength, throw)
return a.val.runtime.defineArrayLength(a.getLengthProp(), descr, a.setLength, throw)
}
return a.baseObject.defineOwnPropertyStr(name, descr, throw)
}
Expand Down Expand Up @@ -412,9 +409,9 @@ func (a *sparseArrayObject) deleteIdx(idx valueInt, throw bool) bool {
return a.baseObject.deleteStr(idx.string(), throw)
}

func (a *sparseArrayObject) sortLen() int64 {
func (a *sparseArrayObject) sortLen() int {
if len(a.items) > 0 {
return int64(a.items[len(a.items)-1].idx) + 1
return toIntStrict(int64(a.items[len(a.items)-1].idx) + 1)
}

return 0
Expand Down Expand Up @@ -463,12 +460,12 @@ func (a *sparseArrayObject) exportToArrayOrSlice(dst reflect.Value, typ reflect.
r := a.val.runtime
if iter := a.getSym(SymIterator, nil); iter == r.global.arrayValues || iter == nil {
l := toIntStrict(int64(a.length))
if dst.Len() != l {
if typ.Kind() == reflect.Array {
if typ.Kind() == reflect.Array {
if dst.Len() != l {
return fmt.Errorf("cannot convert an Array into an array, lengths mismatch (have %d, need %d)", l, dst.Len())
} else {
dst.Set(reflect.MakeSlice(typ, l, l))
}
} else {
dst.Set(reflect.MakeSlice(typ, l, l))
}
ctx.putTyped(a.val, typ, dst.Interface())
for _, item := range a.items {
Expand Down
Loading