@@ -60,7 +60,7 @@ func Test_GetVersion(t *testing.T) {
60
60
61
61
func Test_HelloWorld (t * testing.T ) {
62
62
engine .NewContext (nil ).Scope (func (cs ContextScope ) {
63
- if cs .Eval ([] byte ( "'Hello ' + 'World!'" ) ).ToString () != "Hello World!" {
63
+ if cs .Eval ("'Hello ' + 'World!'" ).ToString () != "Hello World!" {
64
64
t .Fatal ("result not match" )
65
65
}
66
66
})
@@ -157,59 +157,59 @@ func Test_Values(t *testing.T) {
157
157
maxNumber = int64 (maxUint64 )
158
158
)
159
159
160
- if engine .NewBoolean (true ).ToBoolean () != true {
160
+ if cs .NewBoolean (true ).ToBoolean () != true {
161
161
t .Fatal (`NewBoolean(true).ToBoolean() != true` )
162
162
}
163
163
164
- if engine .NewNumber (12.34 ).ToNumber () != 12.34 {
164
+ if cs .NewNumber (12.34 ).ToNumber () != 12.34 {
165
165
t .Fatal (`NewNumber(12.34).ToNumber() != 12.34` )
166
166
}
167
167
168
- if engine .NewNumber (float64 (maxNumber )).ToInteger () != maxNumber {
168
+ if cs .NewNumber (float64 (maxNumber )).ToInteger () != maxNumber {
169
169
t .Fatal (`NewNumber(float64(maxNumber)).ToInteger() != maxNumber` )
170
170
}
171
171
172
- if engine .NewInteger (maxInt32 ).IsInt32 () == false {
172
+ if cs .NewInteger (maxInt32 ).IsInt32 () == false {
173
173
t .Fatal (`NewInteger(maxInt32).IsInt32() == false` )
174
174
}
175
175
176
- if engine .NewInteger (maxUint32 ).IsInt32 () != false {
176
+ if cs .NewInteger (maxUint32 ).IsInt32 () != false {
177
177
t .Fatal (`NewInteger(maxUint32).IsInt32() != false` )
178
178
}
179
179
180
- if engine .NewInteger (maxUint32 ).IsUint32 () == false {
180
+ if cs .NewInteger (maxUint32 ).IsUint32 () == false {
181
181
t .Fatal (`NewInteger(maxUint32).IsUint32() == false` )
182
182
}
183
183
184
- if engine .NewInteger (maxNumber ).ToInteger () != maxNumber {
184
+ if cs .NewInteger (maxNumber ).ToInteger () != maxNumber {
185
185
t .Fatal (`NewInteger(maxNumber).ToInteger() != maxNumber` )
186
186
}
187
187
188
- if engine .NewString ("Hello World!" ).ToString () != "Hello World!" {
188
+ if cs .NewString ("Hello World!" ).ToString () != "Hello World!" {
189
189
t .Fatal (`NewString("Hello World!").ToString() != "Hello World!"` )
190
190
}
191
191
192
- if engine .NewObject ().IsObject () == false {
192
+ if cs .NewObject ().IsObject () == false {
193
193
t .Fatal (`NewObject().IsObject() == false` )
194
194
}
195
195
196
- if engine .NewArray (5 ).IsArray () == false {
196
+ if cs .NewArray (5 ).IsArray () == false {
197
197
t .Fatal (`NewArray(5).IsArray() == false` )
198
198
}
199
199
200
- if engine .NewArray (5 ).ToArray ().Length () != 5 {
200
+ if cs .NewArray (5 ).ToArray ().Length () != 5 {
201
201
t .Fatal (`NewArray(5).Length() != 5` )
202
202
}
203
203
204
- if engine .NewRegExp ("foo" , RF_None ).IsRegExp () == false {
204
+ if cs .NewRegExp ("foo" , RF_None ).IsRegExp () == false {
205
205
t .Fatal (`NewRegExp("foo", RF_None).IsRegExp() == false` )
206
206
}
207
207
208
- if engine .NewRegExp ("foo" , RF_Global ).ToRegExp ().Pattern () != "foo" {
208
+ if cs .NewRegExp ("foo" , RF_Global ).ToRegExp ().Pattern () != "foo" {
209
209
t .Fatal (`NewRegExp("foo", RF_Global).ToRegExp().Pattern() != "foo"` )
210
210
}
211
211
212
- if engine .NewRegExp ("foo" , RF_Global ).ToRegExp ().Flags () != RF_Global {
212
+ if cs .NewRegExp ("foo" , RF_Global ).ToRegExp ().Flags () != RF_Global {
213
213
t .Fatal (`NewRegExp("foo", RF_Global).ToRegExp().Flags() != RF_Global` )
214
214
}
215
215
})
@@ -437,9 +437,9 @@ func Test_Function(t *testing.T) {
437
437
}
438
438
439
439
result := value .ToFunction ().Call (
440
- engine .NewInteger (1 ),
441
- engine .NewInteger (2 ),
442
- engine .NewInteger (3 ),
440
+ cs .NewInteger (1 ),
441
+ cs .NewInteger (2 ),
442
+ cs .NewInteger (3 ),
443
443
)
444
444
445
445
if result .IsNumber () == false {
@@ -462,7 +462,7 @@ func Test_Function(t *testing.T) {
462
462
}
463
463
464
464
if function .ToFunction ().Call (
465
- engine .NewString ("Hello World!" ),
465
+ cs .NewString ("Hello World!" ),
466
466
).IsTrue () == false {
467
467
t .Fatal ("callback return not match" )
468
468
}
@@ -490,11 +490,11 @@ func Test_Accessor(t *testing.T) {
490
490
PA_None ,
491
491
)
492
492
493
- template .SetProperty ("def" , engine .NewInteger (8888 ), PA_None )
493
+ template .SetProperty ("def" , cs .NewInteger (8888 ), PA_None )
494
494
495
495
values := []* Value {
496
496
template .NewObject (), // New
497
- engine .NewObject (), // Wrap
497
+ cs .NewObject (), // Wrap
498
498
}
499
499
template .WrapObject (values [1 ])
500
500
@@ -509,7 +509,7 @@ func Test_Accessor(t *testing.T) {
509
509
t .Fatal (`object.GetProperty("abc").ToInt32() != 1234` )
510
510
}
511
511
512
- object .SetProperty ("abc" , engine .NewInteger (5678 ), PA_None )
512
+ object .SetProperty ("abc" , cs .NewInteger (5678 ), PA_None )
513
513
514
514
if propertyValue != 5678 {
515
515
t .Fatal (`propertyValue != 5678` )
@@ -577,17 +577,17 @@ func Test_NamedPropertyHandler(t *testing.T) {
577
577
object := obj_template .NewObject ().ToObject ()
578
578
579
579
object .GetProperty ("abc" )
580
- object .SetProperty ("abc" , engine .NewInteger (123 ), PA_None )
580
+ object .SetProperty ("abc" , cs .NewInteger (123 ), PA_None )
581
581
object .GetPropertyAttributes ("abc" )
582
582
583
- cs .Eval ([] byte ( `
583
+ cs .Eval (`
584
584
var data = GetData();
585
585
586
586
delete data.abc;
587
587
588
588
for (var p in data) {
589
589
}
590
- ` ))
590
+ ` )
591
591
})
592
592
593
593
if ! (get_called && set_called && query_called && delete_called && enum_called ) {
@@ -646,16 +646,16 @@ func Test_IndexedPropertyHandler(t *testing.T) {
646
646
object := obj_template .NewObject ().ToObject ()
647
647
648
648
object .GetElement (1 )
649
- object .SetElement (1 , engine .NewInteger (123 ))
649
+ object .SetElement (1 , cs .NewInteger (123 ))
650
650
651
- cs .Eval ([] byte ( `
651
+ cs .Eval (`
652
652
var data = GetData();
653
653
654
654
delete data[1];
655
655
656
656
for (var p in data) {
657
657
}
658
- ` ))
658
+ ` )
659
659
})
660
660
661
661
if ! (get_called && set_called && query_called && delete_called && enum_called ) {
@@ -666,59 +666,59 @@ func Test_IndexedPropertyHandler(t *testing.T) {
666
666
}
667
667
668
668
func Test_ObjectConstructor (t * testing.T ) {
669
- engine .NewContext (nil ).Scope (func (cs ContextScope ) {
670
- ftConstructor := engine .NewFunctionTemplate (nil )
671
- ftConstructor .SetClassName ("MyClass" )
669
+ ftConstructor := engine .NewFunctionTemplate (nil )
670
+ ftConstructor .SetClassName ("MyClass" )
672
671
673
- obj_template := ftConstructor .InstanceTemplate ()
672
+ obj_template := ftConstructor .InstanceTemplate ()
674
673
675
- var (
676
- get_called = false
677
- set_called = false
678
- query_called = false
679
- delete_called = false
680
- enum_called = false
681
- )
674
+ var (
675
+ get_called = false
676
+ set_called = false
677
+ query_called = false
678
+ delete_called = false
679
+ enum_called = false
680
+ )
682
681
683
- obj_template .SetNamedPropertyHandler (
684
- func (name string , info PropertyCallbackInfo ) {
685
- //t.Logf("get %s", name)
686
- get_called = get_called || name == "abc"
687
- },
688
- func (name string , value * Value , info PropertyCallbackInfo ) {
689
- //t.Logf("set %s", name)
690
- set_called = set_called || name == "abc"
691
- },
692
- func (name string , info PropertyCallbackInfo ) {
693
- //t.Logf("query %s", name)
694
- query_called = query_called || name == "abc"
695
- },
696
- func (name string , info PropertyCallbackInfo ) {
697
- //t.Logf("delete %s", name)
698
- delete_called = delete_called || name == "abc"
699
- },
700
- func (info PropertyCallbackInfo ) {
701
- //t.Log("enumerate")
702
- enum_called = true
703
- },
704
- nil ,
705
- )
682
+ obj_template .SetNamedPropertyHandler (
683
+ func (name string , info PropertyCallbackInfo ) {
684
+ //t.Logf("get %s", name)
685
+ get_called = get_called || name == "abc"
686
+ },
687
+ func (name string , value * Value , info PropertyCallbackInfo ) {
688
+ //t.Logf("set %s", name)
689
+ set_called = set_called || name == "abc"
690
+ },
691
+ func (name string , info PropertyCallbackInfo ) {
692
+ //t.Logf("query %s", name)
693
+ query_called = query_called || name == "abc"
694
+ },
695
+ func (name string , info PropertyCallbackInfo ) {
696
+ //t.Logf("delete %s", name)
697
+ delete_called = delete_called || name == "abc"
698
+ },
699
+ func (info PropertyCallbackInfo ) {
700
+ //t.Log("enumerate")
701
+ enum_called = true
702
+ },
703
+ nil ,
704
+ )
706
705
706
+ engine .NewContext (nil ).Scope (func (cs ContextScope ) {
707
707
cs .Global ().SetProperty ("MyClass" , ftConstructor .NewFunction (), PA_None )
708
708
709
- if ! cs .Eval ([] byte ( "(new MyClass) instanceof MyClass" ) ).IsTrue () {
709
+ if ! cs .Eval ("(new MyClass) instanceof MyClass" ).IsTrue () {
710
710
t .Fatal ("(new MyClass) instanceof MyClass == false" )
711
711
}
712
712
713
- object := cs .Eval ([] byte ( `
713
+ object := cs .Eval (`
714
714
var data = new MyClass;
715
715
var temp = data.abc;
716
716
data.abc = 1;
717
717
delete data.abc;
718
718
for (var p in data) {
719
719
}
720
720
data;
721
- ` )) .ToObject ()
721
+ ` ).ToObject ()
722
722
723
723
object .GetPropertyAttributes ("abc" )
724
724
@@ -769,7 +769,7 @@ func Test_Context(t *testing.T) {
769
769
}, nil , nil , PA_None )
770
770
771
771
engine .NewContext (globalTemplate ).Scope (func (cs ContextScope ) {
772
- cs .Eval ([] byte ( `log("Hello World!")` ) )
772
+ cs .Eval (`log("Hello World!")` )
773
773
})
774
774
775
775
// Test Global Object
@@ -786,7 +786,7 @@ func Test_Context(t *testing.T) {
786
786
return
787
787
}
788
788
789
- cs .Eval ([] byte ( `println("Hello World!")` ) )
789
+ cs .Eval (`println("Hello World!")` )
790
790
})
791
791
792
792
runtime .GC ()
@@ -1079,7 +1079,7 @@ func Benchmark_NewContext(b *testing.B) {
1079
1079
func Benchmark_NewInteger (b * testing.B ) {
1080
1080
engine .NewContext (nil ).Scope (func (cs ContextScope ) {
1081
1081
for i := 0 ; i < b .N ; i ++ {
1082
- engine .NewInteger (int64 (i ))
1082
+ cs .NewInteger (int64 (i ))
1083
1083
}
1084
1084
})
1085
1085
@@ -1091,7 +1091,7 @@ func Benchmark_NewInteger(b *testing.B) {
1091
1091
func Benchmark_NewString (b * testing.B ) {
1092
1092
engine .NewContext (nil ).Scope (func (cs ContextScope ) {
1093
1093
for i := 0 ; i < b .N ; i ++ {
1094
- engine .NewString ("Hello World!" )
1094
+ cs .NewString ("Hello World!" )
1095
1095
}
1096
1096
})
1097
1097
@@ -1103,7 +1103,7 @@ func Benchmark_NewString(b *testing.B) {
1103
1103
func Benchmark_NewObject (b * testing.B ) {
1104
1104
engine .NewContext (nil ).Scope (func (cs ContextScope ) {
1105
1105
for i := 0 ; i < b .N ; i ++ {
1106
- engine .NewObject ()
1106
+ cs .NewObject ()
1107
1107
}
1108
1108
})
1109
1109
@@ -1115,7 +1115,7 @@ func Benchmark_NewObject(b *testing.B) {
1115
1115
func Benchmark_NewArray0 (b * testing.B ) {
1116
1116
engine .NewContext (nil ).Scope (func (cs ContextScope ) {
1117
1117
for i := 0 ; i < b .N ; i ++ {
1118
- engine .NewArray (0 )
1118
+ cs .NewArray (0 )
1119
1119
}
1120
1120
})
1121
1121
@@ -1127,7 +1127,7 @@ func Benchmark_NewArray0(b *testing.B) {
1127
1127
func Benchmark_NewArray5 (b * testing.B ) {
1128
1128
engine .NewContext (nil ).Scope (func (cs ContextScope ) {
1129
1129
for i := 0 ; i < b .N ; i ++ {
1130
- engine .NewArray (5 )
1130
+ cs .NewArray (5 )
1131
1131
}
1132
1132
})
1133
1133
@@ -1139,7 +1139,7 @@ func Benchmark_NewArray5(b *testing.B) {
1139
1139
func Benchmark_NewArray20 (b * testing.B ) {
1140
1140
engine .NewContext (nil ).Scope (func (cs ContextScope ) {
1141
1141
for i := 0 ; i < b .N ; i ++ {
1142
- engine .NewArray (20 )
1142
+ cs .NewArray (20 )
1143
1143
}
1144
1144
})
1145
1145
@@ -1151,7 +1151,7 @@ func Benchmark_NewArray20(b *testing.B) {
1151
1151
func Benchmark_NewArray100 (b * testing.B ) {
1152
1152
engine .NewContext (nil ).Scope (func (cs ContextScope ) {
1153
1153
for i := 0 ; i < b .N ; i ++ {
1154
- engine .NewArray (100 )
1154
+ cs .NewArray (100 )
1155
1155
}
1156
1156
})
1157
1157
@@ -1316,7 +1316,7 @@ func Benchmark_Setter(b *testing.B) {
1316
1316
b .StartTimer ()
1317
1317
1318
1318
for i := 0 ; i < b .N ; i ++ {
1319
- object .SetProperty ("abc" , engine .NewInteger (5678 ), PA_None )
1319
+ object .SetProperty ("abc" , cs .NewInteger (5678 ), PA_None )
1320
1320
}
1321
1321
})
1322
1322
@@ -1329,7 +1329,7 @@ func Benchmark_TryCatch(b *testing.B) {
1329
1329
engine .NewContext (nil ).Scope (func (cs ContextScope ) {
1330
1330
for i := 0 ; i < b .N ; i ++ {
1331
1331
cs .TryCatch (false , func () {
1332
- cs .Eval ([] byte ( "a[=1;" ) )
1332
+ cs .Eval ("a[=1;" )
1333
1333
})
1334
1334
}
1335
1335
})
0 commit comments