Browse Source

Fixed prototype property lookup.

Dmitry Panov 9 years ago
parent
commit
fdc7513385
2 changed files with 25 additions and 0 deletions
  1. 5 0
      object.go
  2. 20 0
      object_gomap_reflect_test.go

+ 5 - 0
object.go

@@ -155,6 +155,11 @@ func (o *baseObject) hasPropertyStr(name string) bool {
 
 func (o *baseObject) _getStr(name string) Value {
 	p := o.getOwnProp(name)
+
+	if p == nil && o.prototype != nil {
+		p = o.prototype.self.getPropStr(name)
+	}
+
 	if p, ok := p.(*valueProperty); ok {
 		return p.get(o.val)
 	}

+ 20 - 0
object_gomap_reflect_test.go

@@ -100,3 +100,23 @@ func TestGoMapReflectJSON(t *testing.T) {
 		t.Fatalf("Not a function: %v", f)
 	}
 }
+
+func TestGoMapReflectProto(t *testing.T) {
+	const SCRIPT = `
+	m.hasOwnProperty("t");
+	`
+
+	vm := New()
+	m := map[string]string{
+		"t": "42",
+	}
+	vm.Set("m", m)
+	_ = "breakpoint"
+	v, err := vm.RunString(SCRIPT)
+	if err != nil {
+		t.Fatal(err)
+	}
+	if !v.StrictEquals(valueTrue) {
+		t.Fatalf("Expected true, got %v", v)
+	}
+}