|
@@ -334,3 +334,43 @@ func TestGoSliceReflectPopNoPtr(t *testing.T) {
|
|
|
t.Fatal(v)
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+func TestGoSliceReflectLengthProperty(t *testing.T) {
|
|
|
+ vm := New()
|
|
|
+ vm.Set("s", []int{2, 3, 4})
|
|
|
+ _, err := vm.RunString(`
|
|
|
+ if (!s.hasOwnProperty("length")) {
|
|
|
+ throw new Error("hasOwnProperty() returned false");
|
|
|
+ }
|
|
|
+ let desc = Object.getOwnPropertyDescriptor(s, "length");
|
|
|
+ if (desc.value !== 3 || !desc.writable || desc.enumerable || desc.configurable) {
|
|
|
+ throw new Error("incorrect property descriptor: " + JSON.stringify(desc));
|
|
|
+ }
|
|
|
+ `)
|
|
|
+ if err != nil {
|
|
|
+ t.Fatal(err)
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+type testCustomSliceWithMethods []int
|
|
|
+
|
|
|
+func (a testCustomSliceWithMethods) Method() bool {
|
|
|
+ return true
|
|
|
+}
|
|
|
+
|
|
|
+func TestGoSliceReflectMethods(t *testing.T) {
|
|
|
+ vm := New()
|
|
|
+ vm.Set("s", testCustomSliceWithMethods{1, 2, 3})
|
|
|
+ _, err := vm.RunString(`
|
|
|
+ if (!s.hasOwnProperty("Method")) {
|
|
|
+ throw new Error("hasOwnProperty() returned false");
|
|
|
+ }
|
|
|
+ let desc = Object.getOwnPropertyDescriptor(s, "Method");
|
|
|
+ if (desc.value() !== true || desc.writable || !desc.enumerable || desc.configurable) {
|
|
|
+ throw new Error("incorrect property descriptor: " + JSON.stringify(desc));
|
|
|
+ }
|
|
|
+ `)
|
|
|
+ if err != nil {
|
|
|
+ t.Fatal(err)
|
|
|
+ }
|
|
|
+}
|