Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(78)

Side by Side Diff: src/builtins/builtins-callsite.cc

Issue 2275233002: Refactor call site handling for stack formatting (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Remove JSCallSite type Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | src/execution.h » ('j') | src/isolate.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 the V8 project authors. All rights reserved. 1 // Copyright 2016 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/builtins/builtins.h" 5 #include "src/builtins/builtins.h"
6 #include "src/builtins/builtins-utils.h" 6 #include "src/builtins/builtins-utils.h"
7 7
8 #include "src/string-builder.h" 8 #include "src/string-builder.h"
9 #include "src/wasm/wasm-module.h" 9 #include "src/wasm/wasm-module.h"
10 10
11 namespace v8 { 11 namespace v8 {
12 namespace internal { 12 namespace internal {
13 13
14 #define CHECK_CALLSITE(recv, method) \ 14 #define CHECK_CALLSITE(recv, method) \
15 CHECK_RECEIVER(JSObject, recv, method); \ 15 CHECK_RECEIVER(JSObject, recv, method); \
16 if (!JSReceiver::HasOwnProperty( \ 16 if (!JSReceiver::HasOwnProperty( \
17 recv, isolate->factory()->call_site_position_symbol()) \ 17 recv, isolate->factory()->call_site_frame_array_symbol()) \
18 .FromMaybe(false)) { \ 18 .FromMaybe(false)) { \
19 THROW_NEW_ERROR_RETURN_FAILURE( \ 19 THROW_NEW_ERROR_RETURN_FAILURE( \
20 isolate, \ 20 isolate, \
21 NewTypeError(MessageTemplate::kCallSiteMethod, \ 21 NewTypeError(MessageTemplate::kCallSiteMethod, \
22 isolate->factory()->NewStringFromAsciiChecked(method))); \ 22 isolate->factory()->NewStringFromAsciiChecked(method))); \
23 } 23 }
24 24
25 #define CALLSITE_ITER(recv) \
26 Handle<Object> frame_array_obj = JSObject::GetDataProperty( \
27 recv, isolate->factory()->call_site_frame_array_symbol()); \
28 Handle<FrameArray> frame_array = Handle<FrameArray>::cast(frame_array_obj); \
29 \
30 Handle<Object> frame_index_obj = JSObject::GetDataProperty( \
31 recv, isolate->factory()->call_site_frame_index_symbol()); \
32 const int frame_index = Smi::cast(*frame_index_obj)->value(); \
33 \
34 FrameArrayIterator it(isolate, frame_array, frame_index);
35
25 namespace { 36 namespace {
26 37
27 Object* PositiveNumberOrNull(int value, Isolate* isolate) { 38 Object* PositiveNumberOrNull(int value, Isolate* isolate) {
28 if (value >= 0) return *isolate->factory()->NewNumberFromInt(value); 39 if (value >= 0) return *isolate->factory()->NewNumberFromInt(value);
29 return isolate->heap()->null_value(); 40 return isolate->heap()->null_value();
30 } 41 }
31 42
32 } // namespace 43 } // namespace
33 44
34 BUILTIN(CallSitePrototypeGetColumnNumber) { 45 BUILTIN(CallSitePrototypeGetColumnNumber) {
35 HandleScope scope(isolate); 46 HandleScope scope(isolate);
36 CHECK_CALLSITE(recv, "getColumnNumber"); 47 CHECK_CALLSITE(recv, "getColumnNumber");
48 CALLSITE_ITER(recv);
ulan 2016/08/30 10:15:56 We can avoid this macro altogether and replace it
jgruber 2016/08/30 12:11:33 Done.
37 49
38 CallSite call_site(isolate, recv); 50 return PositiveNumberOrNull(it.Frame()->GetColumnNumber(), isolate);
39 CHECK(call_site.IsJavaScript() || call_site.IsWasm());
40 return PositiveNumberOrNull(call_site.GetColumnNumber(), isolate);
41 } 51 }
42 52
43 BUILTIN(CallSitePrototypeGetEvalOrigin) { 53 BUILTIN(CallSitePrototypeGetEvalOrigin) {
44 HandleScope scope(isolate); 54 HandleScope scope(isolate);
45 CHECK_CALLSITE(recv, "getEvalOrigin"); 55 CHECK_CALLSITE(recv, "getEvalOrigin");
46 56 CALLSITE_ITER(recv);
47 CallSite call_site(isolate, recv); 57 return *it.Frame()->GetEvalOrigin();
48 CHECK(call_site.IsJavaScript() || call_site.IsWasm());
49 return *call_site.GetEvalOrigin();
50 } 58 }
51 59
52 BUILTIN(CallSitePrototypeGetFileName) { 60 BUILTIN(CallSitePrototypeGetFileName) {
53 HandleScope scope(isolate); 61 HandleScope scope(isolate);
54 CHECK_CALLSITE(recv, "getFileName"); 62 CHECK_CALLSITE(recv, "getFileName");
55 63 CALLSITE_ITER(recv);
56 CallSite call_site(isolate, recv); 64 return *it.Frame()->GetFileName();
57 CHECK(call_site.IsJavaScript() || call_site.IsWasm());
58 return *call_site.GetFileName();
59 } 65 }
60 66
61 namespace {
62
63 bool CallSiteIsStrict(Isolate* isolate, Handle<JSObject> receiver) {
64 Handle<Object> strict;
65 Handle<Symbol> symbol = isolate->factory()->call_site_strict_symbol();
66 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, strict,
67 JSObject::GetProperty(receiver, symbol));
68 return strict->BooleanValue();
69 }
70
71 } // namespace
72
73 BUILTIN(CallSitePrototypeGetFunction) { 67 BUILTIN(CallSitePrototypeGetFunction) {
74 HandleScope scope(isolate); 68 HandleScope scope(isolate);
75 CHECK_CALLSITE(recv, "getFunction"); 69 CHECK_CALLSITE(recv, "getFunction");
70 CALLSITE_ITER(recv);
76 71
77 if (CallSiteIsStrict(isolate, recv)) 72 StackFrameBase* frame = it.Frame();
78 return *isolate->factory()->undefined_value(); 73 if (frame->IsStrict()) return isolate->heap()->undefined_value();
79 74 return *frame->GetFunction();
80 Handle<Symbol> symbol = isolate->factory()->call_site_function_symbol();
81 RETURN_RESULT_OR_FAILURE(isolate, JSObject::GetProperty(recv, symbol));
82 } 75 }
83 76
84 BUILTIN(CallSitePrototypeGetFunctionName) { 77 BUILTIN(CallSitePrototypeGetFunctionName) {
85 HandleScope scope(isolate); 78 HandleScope scope(isolate);
86 CHECK_CALLSITE(recv, "getFunctionName"); 79 CHECK_CALLSITE(recv, "getFunctionName");
87 80 CALLSITE_ITER(recv);
88 CallSite call_site(isolate, recv); 81 return *it.Frame()->GetFunctionName();
89 CHECK(call_site.IsJavaScript() || call_site.IsWasm());
90 return *call_site.GetFunctionName();
91 } 82 }
92 83
93 BUILTIN(CallSitePrototypeGetLineNumber) { 84 BUILTIN(CallSitePrototypeGetLineNumber) {
94 HandleScope scope(isolate); 85 HandleScope scope(isolate);
95 CHECK_CALLSITE(recv, "getLineNumber"); 86 CHECK_CALLSITE(recv, "getLineNumber");
96 87 CALLSITE_ITER(recv);
97 CallSite call_site(isolate, recv); 88 return PositiveNumberOrNull(it.Frame()->GetLineNumber(), isolate);
98 CHECK(call_site.IsJavaScript() || call_site.IsWasm());
99
100 int line_number = call_site.IsWasm() ? call_site.wasm_func_index()
101 : call_site.GetLineNumber();
102 return PositiveNumberOrNull(line_number, isolate);
103 } 89 }
104 90
105 BUILTIN(CallSitePrototypeGetMethodName) { 91 BUILTIN(CallSitePrototypeGetMethodName) {
106 HandleScope scope(isolate); 92 HandleScope scope(isolate);
107 CHECK_CALLSITE(recv, "getMethodName"); 93 CHECK_CALLSITE(recv, "getMethodName");
108 94 CALLSITE_ITER(recv);
109 CallSite call_site(isolate, recv); 95 return *it.Frame()->GetMethodName();
110 CHECK(call_site.IsJavaScript() || call_site.IsWasm());
111 return *call_site.GetMethodName();
112 } 96 }
113 97
114 BUILTIN(CallSitePrototypeGetPosition) { 98 BUILTIN(CallSitePrototypeGetPosition) {
115 HandleScope scope(isolate); 99 HandleScope scope(isolate);
116 CHECK_CALLSITE(recv, "getPosition"); 100 CHECK_CALLSITE(recv, "getPosition");
117 101 CALLSITE_ITER(recv);
118 Handle<Symbol> symbol = isolate->factory()->call_site_position_symbol(); 102 return Smi::FromInt(it.Frame()->GetPosition());
119 RETURN_RESULT_OR_FAILURE(isolate, JSObject::GetProperty(recv, symbol));
120 } 103 }
121 104
122 BUILTIN(CallSitePrototypeGetScriptNameOrSourceURL) { 105 BUILTIN(CallSitePrototypeGetScriptNameOrSourceURL) {
123 HandleScope scope(isolate); 106 HandleScope scope(isolate);
124 CHECK_CALLSITE(recv, "getScriptNameOrSourceUrl"); 107 CHECK_CALLSITE(recv, "getScriptNameOrSourceUrl");
125 108 CALLSITE_ITER(recv);
126 CallSite call_site(isolate, recv); 109 return *it.Frame()->GetScriptNameOrSourceUrl();
127 CHECK(call_site.IsJavaScript() || call_site.IsWasm());
128 return *call_site.GetScriptNameOrSourceUrl();
129 } 110 }
130 111
131 BUILTIN(CallSitePrototypeGetThis) { 112 BUILTIN(CallSitePrototypeGetThis) {
132 HandleScope scope(isolate); 113 HandleScope scope(isolate);
133 CHECK_CALLSITE(recv, "getThis"); 114 CHECK_CALLSITE(recv, "getThis");
115 CALLSITE_ITER(recv);
134 116
135 if (CallSiteIsStrict(isolate, recv)) 117 StackFrameBase* frame = it.Frame();
136 return *isolate->factory()->undefined_value(); 118 if (frame->IsStrict()) return isolate->heap()->undefined_value();
137 119 return *frame->GetReceiver();
138 Handle<Object> receiver;
139 Handle<Symbol> symbol = isolate->factory()->call_site_receiver_symbol();
140 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, receiver,
141 JSObject::GetProperty(recv, symbol));
142
143 if (*receiver == isolate->heap()->call_site_constructor_symbol())
144 return *isolate->factory()->undefined_value();
145
146 return *receiver;
147 } 120 }
148 121
149 BUILTIN(CallSitePrototypeGetTypeName) { 122 BUILTIN(CallSitePrototypeGetTypeName) {
150 HandleScope scope(isolate); 123 HandleScope scope(isolate);
151 CHECK_CALLSITE(recv, "getTypeName"); 124 CHECK_CALLSITE(recv, "getTypeName");
152 125 CALLSITE_ITER(recv);
153 CallSite call_site(isolate, recv); 126 return *it.Frame()->GetTypeName();
154 CHECK(call_site.IsJavaScript() || call_site.IsWasm());
155 return *call_site.GetTypeName();
156 } 127 }
157 128
158 BUILTIN(CallSitePrototypeIsConstructor) { 129 BUILTIN(CallSitePrototypeIsConstructor) {
159 HandleScope scope(isolate); 130 HandleScope scope(isolate);
160 CHECK_CALLSITE(recv, "isConstructor"); 131 CHECK_CALLSITE(recv, "isConstructor");
161 132 CALLSITE_ITER(recv);
162 CallSite call_site(isolate, recv); 133 return isolate->heap()->ToBoolean(it.Frame()->IsConstructor());
163 CHECK(call_site.IsJavaScript() || call_site.IsWasm());
164 return isolate->heap()->ToBoolean(call_site.IsConstructor());
165 } 134 }
166 135
167 BUILTIN(CallSitePrototypeIsEval) { 136 BUILTIN(CallSitePrototypeIsEval) {
168 HandleScope scope(isolate); 137 HandleScope scope(isolate);
169 CHECK_CALLSITE(recv, "isEval"); 138 CHECK_CALLSITE(recv, "isEval");
170 139 CALLSITE_ITER(recv);
171 CallSite call_site(isolate, recv); 140 return isolate->heap()->ToBoolean(it.Frame()->IsEval());
172 CHECK(call_site.IsJavaScript() || call_site.IsWasm());
173 return isolate->heap()->ToBoolean(call_site.IsEval());
174 } 141 }
175 142
176 BUILTIN(CallSitePrototypeIsNative) { 143 BUILTIN(CallSitePrototypeIsNative) {
177 HandleScope scope(isolate); 144 HandleScope scope(isolate);
178 CHECK_CALLSITE(recv, "isNative"); 145 CHECK_CALLSITE(recv, "isNative");
179 146 CALLSITE_ITER(recv);
180 CallSite call_site(isolate, recv); 147 return isolate->heap()->ToBoolean(it.Frame()->IsNative());
181 CHECK(call_site.IsJavaScript() || call_site.IsWasm());
182 return isolate->heap()->ToBoolean(call_site.IsNative());
183 } 148 }
184 149
185 BUILTIN(CallSitePrototypeIsToplevel) { 150 BUILTIN(CallSitePrototypeIsToplevel) {
186 HandleScope scope(isolate); 151 HandleScope scope(isolate);
187 CHECK_CALLSITE(recv, "isToplevel"); 152 CHECK_CALLSITE(recv, "isToplevel");
188 153 CALLSITE_ITER(recv);
189 CallSite call_site(isolate, recv); 154 return isolate->heap()->ToBoolean(it.Frame()->IsToplevel());
190 CHECK(call_site.IsJavaScript() || call_site.IsWasm());
191 return isolate->heap()->ToBoolean(call_site.IsToplevel());
192 } 155 }
193 156
194 BUILTIN(CallSitePrototypeToString) { 157 BUILTIN(CallSitePrototypeToString) {
195 HandleScope scope(isolate); 158 HandleScope scope(isolate);
196 CHECK_CALLSITE(recv, "toString"); 159 CHECK_CALLSITE(recv, "toString");
197 RETURN_RESULT_OR_FAILURE(isolate, CallSiteUtils::ToString(isolate, recv)); 160 CALLSITE_ITER(recv);
161 RETURN_RESULT_OR_FAILURE(isolate, it.Frame()->ToString());
198 } 162 }
199 163
200 #undef CHECK_CALLSITE 164 #undef CHECK_CALLSITE
201 165
202 } // namespace internal 166 } // namespace internal
203 } // namespace v8 167 } // namespace v8
OLDNEW
« no previous file with comments | « no previous file | src/execution.h » ('j') | src/isolate.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698