forked from facebook/hermes
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunction-toString.js
More file actions
122 lines (97 loc) · 3.59 KB
/
function-toString.js
File metadata and controls
122 lines (97 loc) · 3.59 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/**
* Copyright (c) Facebook, Inc. and its 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 %s | %FileCheck --match-full-lines %s
// RUN: %hermes -O %s | %FileCheck --match-full-lines %s
// RUN: %hermes -lazy %s | %FileCheck --match-full-lines %s
// RUN: %hermes -O -target=HBC %s | %FileCheck --match-full-lines %s
// RUN: %hermes -O -target=HBC -emit-binary -out %t.hbc %s && %hermes %t.hbc | %FileCheck --match-full-lines %s
// UNSUPPORTED: serializer
print('Function.prototype.toString');
// CHECK-LABEL: Function.prototype.toString
/// --- Basics ---
function dflt(x) {};
print(dflt.toString());
// CHECK-NEXT: function dflt(a0) { [bytecode] }
function showSource(x) { 'show source' }
print(showSource.toString());
// CHECK-NEXT: function showSource(x) { 'show source' }
function hideSource(x) { 'hide source' }
print(hideSource.toString());
// CHECK-NEXT: function hideSource() { [native code] }
function sensitive(x) { 'sensitive'; }
print(sensitive.toString());
// CHECK-NEXT: function sensitive() { [native code] }
/// --- Implementation-hidden Functions ---
/// Are indistinguishable with real 0-arity NativeFunctions.
print(Date.now.toString());
// CHECK-NEXT: function now() { [native code] }
print((function now() { 'hide source' }).toString());
// CHECK-NEXT: function now() { [native code] }
/// --- Function Expression ---
print((function fe() { 'show source' }).toString());
// CHECK-NEXT: function fe() { 'show source' }
/// --- Arrow Function Expression ---
print((() => { 'show source' }).toString());
// CHECK-NEXT: () => { 'show source' }
print((() => { 'hide source' }).toString());
// CHECK-NEXT: function () { [native code] }
/// --- Async / Generator Function ---
/// You can tell if a function is async/generator for
/// both the Default and ShowSource source visibility, but
/// not the HideSource and Sensitive.
async function af1() { await 1; };
async function af2() { 'show source'; await 1; };
async function af3() { 'hide source'; await 1; };
async function af4() { 'sensitive'; await 1; };
print(af1.toString());
print(af2.toString());
print(af3.toString());
print(af4.toString());
// CHECK-NEXT: async function af1() { [bytecode] }
// CHECK-NEXT: async function af2() { 'show source'; await 1; }
// CHECK-NEXT: function af3() { [native code] }
// CHECK-NEXT: function af4() { [native code] }
function* gf1() { yield 1; };
function* gf2() { 'show source'; yield 1; };
function* gf3() { 'hide source'; yield 1; };
function* gf4() { 'sensitive'; yield 1; };
print(gf1.toString());
print(gf2.toString());
print(gf3.toString());
print(gf4.toString());
// CHECK-NEXT: function *gf1() { [bytecode] }
// CHECK-NEXT: function* gf2() { 'show source'; yield 1; }
// CHECK-NEXT: function gf3() { [native code] }
// CHECK-NEXT: function gf4() { [native code] }
/// --- "Large" Source ---
function large() {
'show source';
'0123456789abcdef';
'0123456789abcdef';
'0123456789abcdef';
'0123456789abcdef';
'0123456789abcdef';
'0123456789abcdef';
'0123456789abcdef';
'0123456789abcdef';
'0123456789abcdef';
'0123456789abcdef';
}
print(large.toString());
// CHECK-LABEL:function large() {
// CHECK-NEXT: 'show source';
// CHECK-NEXT: '0123456789abcdef';
// CHECK-NEXT: '0123456789abcdef';
// CHECK-NEXT: '0123456789abcdef';
// CHECK-NEXT: '0123456789abcdef';
// CHECK-NEXT: '0123456789abcdef';
// CHECK-NEXT: '0123456789abcdef';
// CHECK-NEXT: '0123456789abcdef';
// CHECK-NEXT: '0123456789abcdef';
// CHECK-NEXT: '0123456789abcdef';
// CHECK-NEXT: '0123456789abcdef';
// CHECK-NEXT:}