forked from facebook/hermes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
store_to_env.js
60 lines (56 loc) · 2.16 KB
/
store_to_env.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
// RUN: %hermes -O -dump-bytecode %s | %FileCheck --match-full-lines %s
function foo() {
var myNum = 1234;
var myBool = true;
var myString = 'a string';
var myObj = new Object();
var myRegExp = /Hermes/i;
var myUndef = 'temp string';
var myFunc = function bar(){
myNum++;
myBool = false;
myString = 'new string';
print(myObj);
print(myRegExp);
myUndef = undefined;
}
return myFunc;
}
// CHECK: Function<foo>(1 params, 10 registers, 3 symbols):
// CHECK-NEXT: Offset in debug table: {{.*}}
// CHECK-NEXT: CreateEnvironment r0
// CHECK-NEXT: LoadConstInt r1, 1234
// CHECK-NEXT: StoreNPToEnvironment r0, 0, r1
// CHECK-NEXT: GetGlobalObject r1
// CHECK-NEXT: TryGetById r1, r1, 1, "Object"
// CHECK-NEXT: GetByIdShort r2, r1, 2, "prototype"
// CHECK-NEXT: CreateThis r2, r2, r1
// CHECK-NEXT: Mov r3, r2
// CHECK-NEXT: Construct r1, r1, 1
// CHECK-NEXT: SelectObject r1, r2, r1
// CHECK-NEXT: StoreToEnvironment r0, 1, r1
// CHECK-NEXT: CreateRegExp r1, "Hermes", "i", 0
// CHECK-NEXT: StoreToEnvironment r0, 2, r1
// CHECK-NEXT: CreateClosure r0, r0, Function<bar>
// CHECK-NEXT: Ret r0
// CHECK: Function<bar>(1 params, 13 registers, 0 symbols):
// CHECK-NEXT: Offset in debug table: {{.*}}
// CHECK-NEXT: GetEnvironment r1, 0
// CHECK-NEXT: LoadFromEnvironment r0, r1, 0
// CHECK-NEXT: Inc r0, r0
// CHECK-NEXT: StoreToEnvironment r1, 0, r0
// CHECK-NEXT: GetGlobalObject r2
// CHECK-NEXT: TryGetById r4, r2, 1, "print"
// CHECK-NEXT: LoadFromEnvironment r3, r1, 1
// CHECK-NEXT: LoadConstUndefined r0
// CHECK-NEXT: Call2 r3, r4, r0, r3
// CHECK-NEXT: TryGetById r2, r2, 1, "print"
// CHECK-NEXT: LoadFromEnvironment r1, r1, 2
// CHECK-NEXT: Call2 r1, r2, r0, r1
// CHECK-NEXT: Ret r0