Browse Source

Merge pull request #425 from mstoykov/fixLengthForImportedStringWithUnicode

Build correct base object from importedString
Dmitry Panov 3 years ago
parent
commit
0c74f9139f
2 changed files with 5 additions and 0 deletions
  1. 4 0
      string_imported.go
  2. 1 0
      string_test.go

+ 4 - 0
string_imported.go

@@ -133,6 +133,10 @@ func (i *importedString) ExportType() reflect.Type {
 }
 }
 
 
 func (i *importedString) baseObject(r *Runtime) *Object {
 func (i *importedString) baseObject(r *Runtime) *Object {
+	i.ensureScanned()
+	if i.u != nil {
+		return i.u.baseObject(r)
+	}
 	return asciiString(i.s).baseObject(r)
 	return asciiString(i.s).baseObject(r)
 }
 }
 
 

+ 1 - 0
string_test.go

@@ -133,6 +133,7 @@ func TestImportedString(t *testing.T) {
 
 
 	for i, a := range strs {
 	for i, a := range strs {
 		testUnaryOp(a, "JSON.parse(JSON.stringify(a))", a, t)
 		testUnaryOp(a, "JSON.parse(JSON.stringify(a))", a, t)
+		testUnaryOp(a, "a.length", int64(len(utf16.Encode([]rune(a)))), t)
 		for j, b := range strs {
 		for j, b := range strs {
 			testBinaryOp(a, b, "a === b", a == b, t)
 			testBinaryOp(a, b, "a === b", a == b, t)
 			testBinaryOp(a, b, "a == b", a == b, t)
 			testBinaryOp(a, b, "a == b", a == b, t)