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

Proxy #135

Merged
merged 29 commits into from
Mar 24, 2020
Merged

Proxy #135

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
3c2137d
Implementation of ES6 Proxy class with native go interceptors as well…
noctarius Jan 12, 2018
30c4a18
ES6 Proxy: made propertyDescr public as PropertyDescriptor for native…
noctarius Jan 13, 2018
adb6916
Added invariants for trap getOwnPropertyDescriptor
noctarius Jan 26, 2018
099c515
fixes apply trap
noctarius Feb 10, 2018
d3ae701
Little fix for stacktraces in intellij and added sourcemap support fo…
noctarius Aug 14, 2017
e521f52
added support for external but local sourcemaps
noctarius Feb 11, 2018
043a4b3
fixed compile
noctarius Feb 11, 2018
019990a
Added some of the requested changes
noctarius Feb 17, 2018
8438e2d
Enabled access to current StackFrames
noctarius Feb 11, 2018
c9e9eb7
Added exported api to create named native function and not to fallbac…
noctarius Feb 21, 2018
d0f5b8c
Merge remote-tracking branch 'remotes/noctarius-es6-proxy/es6-proxy' …
dop251 Mar 11, 2020
59a7fde
[WIP] Proxy
dop251 Mar 11, 2020
b1b1c9e
[WIP] Proxy
dop251 Mar 11, 2020
18db2bf
[WIP] Proxy
dop251 Mar 13, 2020
534cabe
[WIP] Proxy
dop251 Mar 13, 2020
3d41f48
[WIP] Proxy
dop251 Mar 14, 2020
6733eb4
[WIP] Proxy
dop251 Mar 15, 2020
ac6d122
[WIP] Proxy
dop251 Mar 16, 2020
8ab37e7
[WIP] Proxy
dop251 Mar 16, 2020
1d8d028
[WIP] Proxy
dop251 Mar 18, 2020
40796a4
[WIP] Proxy, Reflect
dop251 Mar 19, 2020
265c0f1
[WIP] Proxy, Reflect
dop251 Mar 20, 2020
7e5ec11
[WIP] Proxy, Reflect
dop251 Mar 21, 2020
3173478
[WIP] new.target
dop251 Mar 22, 2020
afb52b1
[WIP] fixed formatting
dop251 Mar 22, 2020
68e29d3
[WIP] fixed formatting
dop251 Mar 22, 2020
ef1aaed
[WIP] __proto__
dop251 Mar 23, 2020
27ab215
[WIP] reinstated intCache
dop251 Mar 23, 2020
0bf2951
[WIP] got rid of assertInt(), assertFloat(), assertString()
dop251 Mar 23, 2020
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
515 changes: 306 additions & 209 deletions array.go

Large diffs are not rendered by default.

349 changes: 171 additions & 178 deletions array_sparse.go

Large diffs are not rendered by default.

83 changes: 77 additions & 6 deletions array_sparse_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package goja

import "testing"
import (
"testing"
)

func TestSparseArraySetLengthWithPropItems(t *testing.T) {
const SCRIPT = `
Expand All @@ -21,9 +23,18 @@ func TestSparseArraySetLengthWithPropItems(t *testing.T) {
}

func TestSparseArraySwitch(t *testing.T) {
const SCRIPT = `
vm := New()
_, err := vm.RunString(`
var a = [];
a[20470] = 5; // switch to sparse
a[20470] = 5; // switch to sparse`)
if err != nil {
t.Fatal(err)
}
a := vm.Get("a").(*Object)
if _, ok := a.self.(*sparseArrayObject); !ok {
t.Fatal("1: array is not sparse")
}
_, err = vm.RunString(`
var cutoffIdx = Math.round(20470 - 20470/8);
for (var i = a.length - 1; i >= cutoffIdx; i--) {
a[i] = i;
Expand All @@ -44,8 +55,14 @@ func TestSparseArraySwitch(t *testing.T) {
if (a[i] !== i) {
throw new Error("Invalid value at " + i + ": " + a[i]);
}
}`)
if err != nil {
t.Fatal(err)
}

if _, ok := a.self.(*arrayObject); !ok {
t.Fatal("2: array is not normal")
}
_, err = vm.RunString(`
// Now try to expand. Should stay a normal array
a[20471] = 20471;
if (a.length != 20472) {
Expand All @@ -62,8 +79,14 @@ func TestSparseArraySwitch(t *testing.T) {
if (a[i] !== i) {
throw new Error("Invalid value at " + i + ": " + a[i]);
}
}`)
if err != nil {
t.Fatal(err)
}

if _, ok := a.self.(*arrayObject); !ok {
t.Fatal("3: array is not normal")
}
_, err = vm.RunString(`
// Delete enough elements for it to become sparse again.
var cutoffIdx1 = Math.round(20472 - 20472/10);
for (var i = cutoffIdx; i < cutoffIdx1; i++) {
Expand Down Expand Up @@ -97,7 +120,55 @@ func TestSparseArraySwitch(t *testing.T) {
if (a[25590] !== 25590) {
throw new Error("Invalid value at 25590: " + a[25590]);
}
`)
if err != nil {
t.Fatal(err)
}
if _, ok := a.self.(*sparseArrayObject); !ok {
t.Fatal("4: array is not sparse")
}
}

func TestSparseArrayOwnKeys(t *testing.T) {
const SCRIPT = `
var a1 = [];
a1[500000] = 1;
var seen = false;
var count = 0;
var keys = Object.keys(a1);
keys.length === 1 && keys[0] === "500000";
`

testScript1(SCRIPT, valueTrue, t)
}

func TestSparseArrayEnumerate(t *testing.T) {
const SCRIPT = `
var a1 = [];
a1[500000] = 1;
var seen = false;
var count = 0;
for (var i in a1) {
if (i === "500000") {
if (seen) {
throw new Error("seen twice");
}
seen = true;
}
count++;
}
seen && count === 1;
`

testScript1(SCRIPT, valueTrue, t)
}

func TestArraySparseMaxLength(t *testing.T) {
const SCRIPT = `
var a = [];
a[4294967294]=1;
a.length === 4294967295 && a[4294967294] === 1;
`

testScript1(SCRIPT, _undefined, t)
testScript1(SCRIPT, valueTrue, t)
}
10 changes: 10 additions & 0 deletions ast/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,11 @@ type (
Idx file.Idx
Initializer Expression
}

MetaProperty struct {
Meta, Property *Identifier
Idx file.Idx
}
)

// _expressionNode
Expand All @@ -197,6 +202,7 @@ func (*StringLiteral) _expressionNode() {}
func (*ThisExpression) _expressionNode() {}
func (*UnaryExpression) _expressionNode() {}
func (*VariableExpression) _expressionNode() {}
func (*MetaProperty) _expressionNode() {}

// ========= //
// Statement //
Expand Down Expand Up @@ -413,6 +419,7 @@ func (self *StringLiteral) Idx0() file.Idx { return self.Idx }
func (self *ThisExpression) Idx0() file.Idx { return self.Idx }
func (self *UnaryExpression) Idx0() file.Idx { return self.Idx }
func (self *VariableExpression) Idx0() file.Idx { return self.Idx }
func (self *MetaProperty) Idx0() file.Idx { return self.Idx }

func (self *BadStatement) Idx0() file.Idx { return self.From }
func (self *BlockStatement) Idx0() file.Idx { return self.LeftBrace }
Expand Down Expand Up @@ -471,6 +478,9 @@ func (self *VariableExpression) Idx1() file.Idx {
}
return self.Initializer.Idx1()
}
func (self *MetaProperty) Idx1() file.Idx {
return self.Property.Idx1()
}

func (self *BadStatement) Idx1() file.Idx { return self.To }
func (self *BlockStatement) Idx1() file.Idx { return self.RightBrace + 1 }
Expand Down
Loading