Browse Source

Set propValueCount on tagged template arrays. Fixes #366.

Dmitry Panov 3 years ago
parent
commit
261677941f
2 changed files with 15 additions and 3 deletions
  1. 7 3
      vm.go
  2. 8 0
      vm_test.go

+ 7 - 3
vm.go

@@ -4083,7 +4083,7 @@ type getTaggedTmplObject struct {
 
 // As tagged template objects are not cached (because it's hard to ensure the cache is cleaned without using
 // finalizers) this wrapper is needed to override the equality method so that two objects for the same template
-// literal appeared be equal from the code's point of view.
+// literal appeared to be equal from the code's point of view.
 type taggedTemplateArray struct {
 	*arrayObject
 	idPtr *[]Value
@@ -4099,11 +4099,15 @@ func (a *taggedTemplateArray) equal(other objectImpl) bool {
 func (c *getTaggedTmplObject) exec(vm *vm) {
 	cooked := vm.r.newArrayObject()
 	setArrayValues(cooked, c.cooked)
-	cooked.lengthProp.writable = false
-
 	raw := vm.r.newArrayObject()
 	setArrayValues(raw, c.raw)
+
+	cooked.propValueCount = len(c.cooked)
+	cooked.lengthProp.writable = false
+
+	raw.propValueCount = len(c.raw)
 	raw.lengthProp.writable = false
+
 	raw.preventExtensions(true)
 	raw.val.self = &taggedTemplateArray{
 		arrayObject: raw,

+ 8 - 0
vm_test.go

@@ -6,6 +6,14 @@ import (
 	"testing"
 )
 
+func TestTaggedTemplateArgExport(t *testing.T) {
+	vm := New()
+	vm.Set("f", func(v Value) {
+		v.Export()
+	})
+	vm.RunString("f`test`")
+}
+
 func TestVM1(t *testing.T) {
 	r := &Runtime{}
 	r.init()