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

Side by Side Diff: src/messages.cc

Issue 1909353002: [wasm] Make wasm info available on the stack trace (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@wasm-offset-table-3
Patch Set: rebase Created 4 years, 7 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
OLDNEW
1 // Copyright 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 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/messages.h" 5 #include "src/messages.h"
6 6
7 #include "src/api.h" 7 #include "src/api.h"
8 #include "src/execution.h" 8 #include "src/execution.h"
9 #include "src/isolate-inl.h" 9 #include "src/isolate-inl.h"
10 #include "src/string-builder.h" 10 #include "src/string-builder.h"
11 #include "src/wasm/wasm-module.h"
11 12
12 namespace v8 { 13 namespace v8 {
13 namespace internal { 14 namespace internal {
14 15
15 MessageLocation::MessageLocation(Handle<Script> script, int start_pos, 16 MessageLocation::MessageLocation(Handle<Script> script, int start_pos,
16 int end_pos) 17 int end_pos)
17 : script_(script), start_pos_(start_pos), end_pos_(end_pos) {} 18 : script_(script), start_pos_(start_pos), end_pos_(end_pos) {}
18 MessageLocation::MessageLocation(Handle<Script> script, int start_pos, 19 MessageLocation::MessageLocation(Handle<Script> script, int start_pos,
19 int end_pos, Handle<JSFunction> function) 20 int end_pos, Handle<JSFunction> function)
20 : script_(script), 21 : script_(script),
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 Isolate* isolate, Handle<Object> data) { 162 Isolate* isolate, Handle<Object> data) {
162 HandleScope scope(isolate); 163 HandleScope scope(isolate);
163 return GetMessage(isolate, data)->ToCString(DISALLOW_NULLS); 164 return GetMessage(isolate, data)->ToCString(DISALLOW_NULLS);
164 } 165 }
165 166
166 167
167 CallSite::CallSite(Isolate* isolate, Handle<JSObject> call_site_obj) 168 CallSite::CallSite(Isolate* isolate, Handle<JSObject> call_site_obj)
168 : isolate_(isolate) { 169 : isolate_(isolate) {
169 Handle<Object> maybe_function = JSObject::GetDataProperty( 170 Handle<Object> maybe_function = JSObject::GetDataProperty(
170 call_site_obj, isolate->factory()->call_site_function_symbol()); 171 call_site_obj, isolate->factory()->call_site_function_symbol());
171 if (!maybe_function->IsJSFunction()) return; 172 Handle<Object> maybe_wasm_func_index;
173 if (maybe_function->IsJSFunction()) {
174 // javascript
175 fun_ = Handle<JSFunction>::cast(maybe_function);
176 receiver_ = JSObject::GetDataProperty(
177 call_site_obj, isolate->factory()->call_site_receiver_symbol());
178 } else if (!(maybe_wasm_func_index = JSObject::GetDataProperty(
Yang 2016/05/03 18:59:08 Please don't do assignments inside an if-expressio
Clemens Hammacher 2016/05/04 09:06:20 Done.
179 call_site_obj,
180 isolate->factory()->call_site_wasm_func_index_symbol()))
181 ->IsUndefined()) {
182 // wasm
183 wasm_obj_ = JSObject::GetDataProperty(
184 call_site_obj, isolate->factory()->call_site_wasm_obj_symbol());
185 CHECK(maybe_wasm_func_index->ToUint32(&wasm_func_index_));
186 } else {
187 return;
188 }
172 189
173 fun_ = Handle<JSFunction>::cast(maybe_function);
174 receiver_ = JSObject::GetDataProperty(
175 call_site_obj, isolate->factory()->call_site_receiver_symbol());
176 CHECK(JSObject::GetDataProperty( 190 CHECK(JSObject::GetDataProperty(
177 call_site_obj, isolate->factory()->call_site_position_symbol()) 191 call_site_obj, isolate->factory()->call_site_position_symbol())
178 ->ToInt32(&pos_)); 192 ->ToInt32(&pos_));
179 } 193 }
180 194
181 195
182 Handle<Object> CallSite::GetFileName() { 196 Handle<Object> CallSite::GetFileName() {
183 Handle<Object> script(fun_->shared()->script(), isolate_); 197 Object* script;
184 if (script->IsScript()) { 198 if (!IsJavaScript() || !(script = fun_->shared()->script())->IsScript())
Yang 2016/05/03 18:59:08 same here. No assignments inside if-expression. An
Clemens Hammacher 2016/05/04 09:06:20 Done.
185 return Handle<Object>(Handle<Script>::cast(script)->name(), isolate_); 199 return isolate_->factory()->null_value();
186 } 200 return Handle<Object>(Script::cast(script)->name(), isolate_);
187 return isolate_->factory()->null_value();
188 } 201 }
189 202
190 203
191 Handle<Object> CallSite::GetFunctionName() { 204 Handle<Object> CallSite::GetFunctionName() {
205 if (IsWasm()) {
206 if (wasm_obj_->IsUndefined()) return isolate_->factory()->null_value();
207 // wasm_obj_ can be a String if we generate WASM code directly in a test
Yang 2016/05/03 18:59:08 That... is really weird and sounds like a hack. Wh
Clemens Hammacher 2016/05/04 09:06:20 See above.
Yang 2016/05/04 12:04:27 So, like above, can we hide this detail (introduce
208 // case.
209 if (wasm_obj_->IsString()) return wasm_obj_;
210 return wasm::GetWasmFunctionName(Handle<JSObject>::cast(wasm_obj_),
211 wasm_func_index_);
212 }
192 Handle<String> result = JSFunction::GetName(fun_); 213 Handle<String> result = JSFunction::GetName(fun_);
193 if (result->length() != 0) return result; 214 if (result->length() != 0) return result;
194 215
195 Handle<Object> script(fun_->shared()->script(), isolate_); 216 Handle<Object> script(fun_->shared()->script(), isolate_);
196 if (script->IsScript() && 217 if (script->IsScript() &&
197 Handle<Script>::cast(script)->compilation_type() == 218 Handle<Script>::cast(script)->compilation_type() ==
198 Script::COMPILATION_TYPE_EVAL) { 219 Script::COMPILATION_TYPE_EVAL) {
199 return isolate_->factory()->eval_string(); 220 return isolate_->factory()->eval_string();
200 } 221 }
201 return isolate_->factory()->null_value(); 222 return isolate_->factory()->null_value();
202 } 223 }
203 224
204
205 Handle<Object> CallSite::GetScriptNameOrSourceUrl() { 225 Handle<Object> CallSite::GetScriptNameOrSourceUrl() {
206 Handle<Object> script_obj(fun_->shared()->script(), isolate_); 226 Object* script_obj;
207 if (script_obj->IsScript()) { 227 if (!IsJavaScript() || !(script_obj = fun_->shared()->script())->IsScript())
Yang 2016/05/03 18:59:08 same as above.
Clemens Hammacher 2016/05/04 09:06:20 Done.
208 Handle<Script> script = Handle<Script>::cast(script_obj); 228 return isolate_->factory()->null_value();
209 Object* source_url = script->source_url(); 229 Handle<Script> script(Script::cast(script_obj), isolate_);
210 if (source_url->IsString()) return Handle<Object>(source_url, isolate_); 230 Object* source_url = script->source_url();
211 return Handle<Object>(script->name(), isolate_); 231 if (source_url->IsString()) return Handle<Object>(source_url, isolate_);
212 } 232 return Handle<Object>(script->name(), isolate_);
213 return isolate_->factory()->null_value();
214 } 233 }
215 234
216
217 bool CheckMethodName(Isolate* isolate, Handle<JSObject> obj, Handle<Name> name, 235 bool CheckMethodName(Isolate* isolate, Handle<JSObject> obj, Handle<Name> name,
218 Handle<JSFunction> fun, 236 Handle<JSFunction> fun,
219 LookupIterator::Configuration config) { 237 LookupIterator::Configuration config) {
220 LookupIterator iter = 238 LookupIterator iter =
221 LookupIterator::PropertyOrElement(isolate, obj, name, config); 239 LookupIterator::PropertyOrElement(isolate, obj, name, config);
222 if (iter.state() == LookupIterator::DATA) { 240 if (iter.state() == LookupIterator::DATA) {
223 return iter.GetDataValue().is_identical_to(fun); 241 return iter.GetDataValue().is_identical_to(fun);
224 } else if (iter.state() == LookupIterator::ACCESSOR) { 242 } else if (iter.state() == LookupIterator::ACCESSOR) {
225 Handle<Object> accessors = iter.GetAccessors(); 243 Handle<Object> accessors = iter.GetAccessors();
226 if (accessors->IsAccessorPair()) { 244 if (accessors->IsAccessorPair()) {
227 Handle<AccessorPair> pair = Handle<AccessorPair>::cast(accessors); 245 Handle<AccessorPair> pair = Handle<AccessorPair>::cast(accessors);
228 return pair->getter() == *fun || pair->setter() == *fun; 246 return pair->getter() == *fun || pair->setter() == *fun;
229 } 247 }
230 } 248 }
231 return false; 249 return false;
232 } 250 }
233 251
234 252
235 Handle<Object> CallSite::GetMethodName() { 253 Handle<Object> CallSite::GetMethodName() {
236 if (receiver_->IsNull() || receiver_->IsUndefined()) { 254 if (!IsJavaScript() || receiver_->IsNull() || receiver_->IsUndefined()) {
237 return isolate_->factory()->null_value(); 255 return isolate_->factory()->null_value();
238 } 256 }
239 Handle<JSReceiver> receiver = 257 Handle<JSReceiver> receiver =
240 Object::ToObject(isolate_, receiver_).ToHandleChecked(); 258 Object::ToObject(isolate_, receiver_).ToHandleChecked();
241 if (!receiver->IsJSObject()) { 259 if (!receiver->IsJSObject()) {
242 return isolate_->factory()->null_value(); 260 return isolate_->factory()->null_value();
243 } 261 }
244 262
245 Handle<JSObject> obj = Handle<JSObject>::cast(receiver); 263 Handle<JSObject> obj = Handle<JSObject>::cast(receiver);
246 Handle<Object> function_name(fun_->shared()->name(), isolate_); 264 Handle<Object> function_name(fun_->shared()->name(), isolate_);
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 result = inner_scope.CloseAndEscape(name_key); 302 result = inner_scope.CloseAndEscape(name_key);
285 } 303 }
286 } 304 }
287 305
288 if (!result.is_null()) return outer_scope.CloseAndEscape(result); 306 if (!result.is_null()) return outer_scope.CloseAndEscape(result);
289 return isolate_->factory()->null_value(); 307 return isolate_->factory()->null_value();
290 } 308 }
291 309
292 310
293 int CallSite::GetLineNumber() { 311 int CallSite::GetLineNumber() {
294 if (pos_ >= 0) { 312 if (pos_ >= 0 && IsJavaScript()) {
295 Handle<Object> script_obj(fun_->shared()->script(), isolate_); 313 Handle<Object> script_obj(fun_->shared()->script(), isolate_);
296 if (script_obj->IsScript()) { 314 if (script_obj->IsScript()) {
297 Handle<Script> script = Handle<Script>::cast(script_obj); 315 Handle<Script> script = Handle<Script>::cast(script_obj);
298 return Script::GetLineNumber(script, pos_) + 1; 316 return Script::GetLineNumber(script, pos_) + 1;
299 } 317 }
300 } 318 }
301 return -1; 319 return -1;
302 } 320 }
303 321
304 322
305 int CallSite::GetColumnNumber() { 323 int CallSite::GetColumnNumber() {
306 if (pos_ >= 0) { 324 if (pos_ >= 0 && IsJavaScript()) {
307 Handle<Object> script_obj(fun_->shared()->script(), isolate_); 325 Handle<Object> script_obj(fun_->shared()->script(), isolate_);
308 if (script_obj->IsScript()) { 326 if (script_obj->IsScript()) {
309 Handle<Script> script = Handle<Script>::cast(script_obj); 327 Handle<Script> script = Handle<Script>::cast(script_obj);
310 return Script::GetColumnNumber(script, pos_) + 1; 328 return Script::GetColumnNumber(script, pos_) + 1;
311 } 329 }
312 } 330 }
313 return -1; 331 return -1;
314 } 332 }
315 333
316 334
317 bool CallSite::IsNative() { 335 bool CallSite::IsNative() {
336 if (!IsJavaScript()) return false;
318 Handle<Object> script(fun_->shared()->script(), isolate_); 337 Handle<Object> script(fun_->shared()->script(), isolate_);
319 return script->IsScript() && 338 return script->IsScript() &&
320 Handle<Script>::cast(script)->type() == Script::TYPE_NATIVE; 339 Handle<Script>::cast(script)->type() == Script::TYPE_NATIVE;
321 } 340 }
322 341
323 342
324 bool CallSite::IsToplevel() { 343 bool CallSite::IsToplevel() {
344 if (IsWasm()) return false;
325 return receiver_->IsJSGlobalProxy() || receiver_->IsNull() || 345 return receiver_->IsJSGlobalProxy() || receiver_->IsNull() ||
326 receiver_->IsUndefined(); 346 receiver_->IsUndefined();
327 } 347 }
328 348
329 349
330 bool CallSite::IsEval() { 350 bool CallSite::IsEval() {
351 if (!IsJavaScript()) return false;
331 Handle<Object> script(fun_->shared()->script(), isolate_); 352 Handle<Object> script(fun_->shared()->script(), isolate_);
332 return script->IsScript() && 353 return script->IsScript() &&
333 Handle<Script>::cast(script)->compilation_type() == 354 Handle<Script>::cast(script)->compilation_type() ==
334 Script::COMPILATION_TYPE_EVAL; 355 Script::COMPILATION_TYPE_EVAL;
335 } 356 }
336 357
337 358
338 bool CallSite::IsConstructor() { 359 bool CallSite::IsConstructor() {
339 if (!receiver_->IsJSObject()) return false; 360 if (!IsJavaScript() || !receiver_->IsJSObject()) return false;
340 Handle<Object> constructor = 361 Handle<Object> constructor =
341 JSReceiver::GetDataProperty(Handle<JSObject>::cast(receiver_), 362 JSReceiver::GetDataProperty(Handle<JSObject>::cast(receiver_),
342 isolate_->factory()->constructor_string()); 363 isolate_->factory()->constructor_string());
343 return constructor.is_identical_to(fun_); 364 return constructor.is_identical_to(fun_);
344 } 365 }
345 366
346 367
347 Handle<String> MessageTemplate::FormatMessage(Isolate* isolate, 368 Handle<String> MessageTemplate::FormatMessage(Isolate* isolate,
348 int template_index, 369 int template_index,
349 Handle<Object> arg) { 370 Handle<Object> arg) {
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
421 builder.AppendCharacter(*c); 442 builder.AppendCharacter(*c);
422 } 443 }
423 } 444 }
424 445
425 return builder.Finish(); 446 return builder.Finish();
426 } 447 }
427 448
428 449
429 } // namespace internal 450 } // namespace internal
430 } // namespace v8 451 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698