Skip to content

Commit

Permalink
Set propValueCount on tagged template arrays. Fixes dop251#366.
Browse files Browse the repository at this point in the history
  • Loading branch information
dop251 committed Jan 10, 2022
1 parent ddea1f4 commit 2616779
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
10 changes: 7 additions & 3 deletions vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down
8 changes: 8 additions & 0 deletions vm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 2616779

Please sign in to comment.