| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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/isolate.h" | 5 #include "src/isolate.h" |
| 6 | 6 |
| 7 #include <stdlib.h> | 7 #include <stdlib.h> |
| 8 | 8 |
| 9 #include <fstream> // NOLINT(readability/streams) | 9 #include <fstream> // NOLINT(readability/streams) |
| 10 #include <sstream> | 10 #include <sstream> |
| (...skipping 589 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 600 return stack_frame; | 600 return stack_frame; |
| 601 } | 601 } |
| 602 | 602 |
| 603 Handle<JSObject> NewStackFrameObject(WasmFrame* frame) { | 603 Handle<JSObject> NewStackFrameObject(WasmFrame* frame) { |
| 604 Handle<JSObject> stack_frame = | 604 Handle<JSObject> stack_frame = |
| 605 factory()->NewJSObject(isolate_->object_function()); | 605 factory()->NewJSObject(isolate_->object_function()); |
| 606 | 606 |
| 607 if (!function_key_.is_null()) { | 607 if (!function_key_.is_null()) { |
| 608 Object* wasm_object = frame->wasm_obj(); | 608 Object* wasm_object = frame->wasm_obj(); |
| 609 Handle<String> name; | 609 Handle<String> name; |
| 610 if (!wasm_object->IsUndefined()) { | 610 if (!wasm_object->IsUndefined(isolate_)) { |
| 611 Handle<JSObject> wasm = handle(JSObject::cast(wasm_object)); | 611 Handle<JSObject> wasm = handle(JSObject::cast(wasm_object)); |
| 612 wasm::GetWasmFunctionName(wasm, frame->function_index()) | 612 wasm::GetWasmFunctionName(wasm, frame->function_index()) |
| 613 .ToHandle(&name); | 613 .ToHandle(&name); |
| 614 } | 614 } |
| 615 if (name.is_null()) { | 615 if (name.is_null()) { |
| 616 name = isolate_->factory()->NewStringFromStaticChars("<WASM UNNAMED>"); | 616 name = isolate_->factory()->NewStringFromStaticChars("<WASM UNNAMED>"); |
| 617 } | 617 } |
| 618 JSObject::AddProperty(stack_frame, function_key_, name, NONE); | 618 JSObject::AddProperty(stack_frame, function_key_, name, NONE); |
| 619 } | 619 } |
| 620 // Encode the function index as line number. | 620 // Encode the function index as line number. |
| (...skipping 764 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1385 } | 1385 } |
| 1386 | 1386 |
| 1387 bool Isolate::ComputeLocation(MessageLocation* target) { | 1387 bool Isolate::ComputeLocation(MessageLocation* target) { |
| 1388 StackTraceFrameIterator it(this); | 1388 StackTraceFrameIterator it(this); |
| 1389 if (it.done()) return false; | 1389 if (it.done()) return false; |
| 1390 StandardFrame* frame = it.frame(); | 1390 StandardFrame* frame = it.frame(); |
| 1391 // TODO(clemensh): handle wasm frames | 1391 // TODO(clemensh): handle wasm frames |
| 1392 if (!frame->is_java_script()) return false; | 1392 if (!frame->is_java_script()) return false; |
| 1393 JSFunction* fun = JavaScriptFrame::cast(frame)->function(); | 1393 JSFunction* fun = JavaScriptFrame::cast(frame)->function(); |
| 1394 Object* script = fun->shared()->script(); | 1394 Object* script = fun->shared()->script(); |
| 1395 if (!script->IsScript() || (Script::cast(script)->source()->IsUndefined())) { | 1395 if (!script->IsScript() || |
| 1396 (Script::cast(script)->source()->IsUndefined(this))) { |
| 1396 return false; | 1397 return false; |
| 1397 } | 1398 } |
| 1398 Handle<Script> casted_script(Script::cast(script)); | 1399 Handle<Script> casted_script(Script::cast(script)); |
| 1399 // Compute the location from the function and the relocation info of the | 1400 // Compute the location from the function and the relocation info of the |
| 1400 // baseline code. For optimized code this will use the deoptimization | 1401 // baseline code. For optimized code this will use the deoptimization |
| 1401 // information to get canonical location information. | 1402 // information to get canonical location information. |
| 1402 List<FrameSummary> frames(FLAG_max_inlining_levels + 1); | 1403 List<FrameSummary> frames(FLAG_max_inlining_levels + 1); |
| 1403 JavaScriptFrame::cast(frame)->Summarize(&frames); | 1404 JavaScriptFrame::cast(frame)->Summarize(&frames); |
| 1404 FrameSummary& summary = frames.last(); | 1405 FrameSummary& summary = frames.last(); |
| 1405 int pos = summary.abstract_code()->SourcePosition(summary.code_offset()); | 1406 int pos = summary.abstract_code()->SourcePosition(summary.code_offset()); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1450 Handle<Object> fun_obj = handle(elements->get(i + 1), this); | 1451 Handle<Object> fun_obj = handle(elements->get(i + 1), this); |
| 1451 if (fun_obj->IsSmi()) { | 1452 if (fun_obj->IsSmi()) { |
| 1452 // TODO(clemensh): handle wasm frames | 1453 // TODO(clemensh): handle wasm frames |
| 1453 return false; | 1454 return false; |
| 1454 } | 1455 } |
| 1455 Handle<JSFunction> fun = Handle<JSFunction>::cast(fun_obj); | 1456 Handle<JSFunction> fun = Handle<JSFunction>::cast(fun_obj); |
| 1456 if (!fun->shared()->IsSubjectToDebugging()) continue; | 1457 if (!fun->shared()->IsSubjectToDebugging()) continue; |
| 1457 | 1458 |
| 1458 Object* script = fun->shared()->script(); | 1459 Object* script = fun->shared()->script(); |
| 1459 if (script->IsScript() && | 1460 if (script->IsScript() && |
| 1460 !(Script::cast(script)->source()->IsUndefined())) { | 1461 !(Script::cast(script)->source()->IsUndefined(this))) { |
| 1461 int pos = PositionFromStackTrace(elements, i); | 1462 int pos = PositionFromStackTrace(elements, i); |
| 1462 Handle<Script> casted_script(Script::cast(script)); | 1463 Handle<Script> casted_script(Script::cast(script)); |
| 1463 *target = MessageLocation(casted_script, pos, pos + 1); | 1464 *target = MessageLocation(casted_script, pos, pos + 1); |
| 1464 return true; | 1465 return true; |
| 1465 } | 1466 } |
| 1466 } | 1467 } |
| 1467 return false; | 1468 return false; |
| 1468 } | 1469 } |
| 1469 | 1470 |
| 1470 | 1471 |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1574 bool should_report_exception; | 1575 bool should_report_exception; |
| 1575 if (IsExternalHandlerOnTop(exception)) { | 1576 if (IsExternalHandlerOnTop(exception)) { |
| 1576 // Only report the exception if the external handler is verbose. | 1577 // Only report the exception if the external handler is verbose. |
| 1577 should_report_exception = try_catch_handler()->is_verbose_; | 1578 should_report_exception = try_catch_handler()->is_verbose_; |
| 1578 } else { | 1579 } else { |
| 1579 // Report the exception if it isn't caught by JavaScript code. | 1580 // Report the exception if it isn't caught by JavaScript code. |
| 1580 should_report_exception = !IsJavaScriptHandlerOnTop(exception); | 1581 should_report_exception = !IsJavaScriptHandlerOnTop(exception); |
| 1581 } | 1582 } |
| 1582 | 1583 |
| 1583 // Actually report the pending message to all message handlers. | 1584 // Actually report the pending message to all message handlers. |
| 1584 if (!message_obj->IsTheHole() && should_report_exception) { | 1585 if (!message_obj->IsTheHole(this) && should_report_exception) { |
| 1585 HandleScope scope(this); | 1586 HandleScope scope(this); |
| 1586 Handle<JSMessageObject> message(JSMessageObject::cast(message_obj)); | 1587 Handle<JSMessageObject> message(JSMessageObject::cast(message_obj)); |
| 1587 Handle<JSValue> script_wrapper(JSValue::cast(message->script())); | 1588 Handle<JSValue> script_wrapper(JSValue::cast(message->script())); |
| 1588 Handle<Script> script(Script::cast(script_wrapper->value())); | 1589 Handle<Script> script(Script::cast(script_wrapper->value())); |
| 1589 int start_pos = message->start_position(); | 1590 int start_pos = message->start_position(); |
| 1590 int end_pos = message->end_position(); | 1591 int end_pos = message->end_position(); |
| 1591 MessageLocation location(script, start_pos, end_pos); | 1592 MessageLocation location(script, start_pos, end_pos); |
| 1592 MessageHandler::ReportMessage(this, &location, message); | 1593 MessageHandler::ReportMessage(this, &location, message); |
| 1593 } | 1594 } |
| 1594 } | 1595 } |
| 1595 | 1596 |
| 1596 | 1597 |
| 1597 MessageLocation Isolate::GetMessageLocation() { | 1598 MessageLocation Isolate::GetMessageLocation() { |
| 1598 DCHECK(has_pending_exception()); | 1599 DCHECK(has_pending_exception()); |
| 1599 | 1600 |
| 1600 if (thread_local_top_.pending_exception_ != heap()->termination_exception() && | 1601 if (thread_local_top_.pending_exception_ != heap()->termination_exception() && |
| 1601 !thread_local_top_.pending_message_obj_->IsTheHole()) { | 1602 !thread_local_top_.pending_message_obj_->IsTheHole(this)) { |
| 1602 Handle<JSMessageObject> message_obj( | 1603 Handle<JSMessageObject> message_obj( |
| 1603 JSMessageObject::cast(thread_local_top_.pending_message_obj_)); | 1604 JSMessageObject::cast(thread_local_top_.pending_message_obj_)); |
| 1604 Handle<JSValue> script_wrapper(JSValue::cast(message_obj->script())); | 1605 Handle<JSValue> script_wrapper(JSValue::cast(message_obj->script())); |
| 1605 Handle<Script> script(Script::cast(script_wrapper->value())); | 1606 Handle<Script> script(Script::cast(script_wrapper->value())); |
| 1606 int start_pos = message_obj->start_position(); | 1607 int start_pos = message_obj->start_position(); |
| 1607 int end_pos = message_obj->end_position(); | 1608 int end_pos = message_obj->end_position(); |
| 1608 return MessageLocation(script, start_pos, end_pos); | 1609 return MessageLocation(script, start_pos, end_pos); |
| 1609 } | 1610 } |
| 1610 | 1611 |
| 1611 return MessageLocation(); | 1612 return MessageLocation(); |
| (...skipping 551 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2163 try_catch_handler()->has_terminated_ = true; | 2164 try_catch_handler()->has_terminated_ = true; |
| 2164 try_catch_handler()->exception_ = heap()->null_value(); | 2165 try_catch_handler()->exception_ = heap()->null_value(); |
| 2165 } else { | 2166 } else { |
| 2166 v8::TryCatch* handler = try_catch_handler(); | 2167 v8::TryCatch* handler = try_catch_handler(); |
| 2167 DCHECK(thread_local_top_.pending_message_obj_->IsJSMessageObject() || | 2168 DCHECK(thread_local_top_.pending_message_obj_->IsJSMessageObject() || |
| 2168 thread_local_top_.pending_message_obj_->IsTheHole()); | 2169 thread_local_top_.pending_message_obj_->IsTheHole()); |
| 2169 handler->can_continue_ = true; | 2170 handler->can_continue_ = true; |
| 2170 handler->has_terminated_ = false; | 2171 handler->has_terminated_ = false; |
| 2171 handler->exception_ = pending_exception(); | 2172 handler->exception_ = pending_exception(); |
| 2172 // Propagate to the external try-catch only if we got an actual message. | 2173 // Propagate to the external try-catch only if we got an actual message. |
| 2173 if (thread_local_top_.pending_message_obj_->IsTheHole()) return true; | 2174 if (thread_local_top_.pending_message_obj_->IsTheHole(this)) return true; |
| 2174 | 2175 |
| 2175 handler->message_obj_ = thread_local_top_.pending_message_obj_; | 2176 handler->message_obj_ = thread_local_top_.pending_message_obj_; |
| 2176 } | 2177 } |
| 2177 return true; | 2178 return true; |
| 2178 } | 2179 } |
| 2179 | 2180 |
| 2180 | 2181 |
| 2181 void Isolate::InitializeLoggingAndCounters() { | 2182 void Isolate::InitializeLoggingAndCounters() { |
| 2182 if (logger_ == NULL) { | 2183 if (logger_ == NULL) { |
| 2183 logger_ = new Logger(this); | 2184 logger_ = new Logger(this); |
| (...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2505 CodeTracer* Isolate::GetCodeTracer() { | 2506 CodeTracer* Isolate::GetCodeTracer() { |
| 2506 if (code_tracer() == NULL) set_code_tracer(new CodeTracer(id())); | 2507 if (code_tracer() == NULL) set_code_tracer(new CodeTracer(id())); |
| 2507 return code_tracer(); | 2508 return code_tracer(); |
| 2508 } | 2509 } |
| 2509 | 2510 |
| 2510 Map* Isolate::get_initial_js_array_map(ElementsKind kind) { | 2511 Map* Isolate::get_initial_js_array_map(ElementsKind kind) { |
| 2511 if (IsFastElementsKind(kind)) { | 2512 if (IsFastElementsKind(kind)) { |
| 2512 DisallowHeapAllocation no_gc; | 2513 DisallowHeapAllocation no_gc; |
| 2513 Object* const initial_js_array_map = | 2514 Object* const initial_js_array_map = |
| 2514 context()->native_context()->get(Context::ArrayMapIndex(kind)); | 2515 context()->native_context()->get(Context::ArrayMapIndex(kind)); |
| 2515 if (!initial_js_array_map->IsUndefined()) { | 2516 if (!initial_js_array_map->IsUndefined(this)) { |
| 2516 return Map::cast(initial_js_array_map); | 2517 return Map::cast(initial_js_array_map); |
| 2517 } | 2518 } |
| 2518 } | 2519 } |
| 2519 return nullptr; | 2520 return nullptr; |
| 2520 } | 2521 } |
| 2521 | 2522 |
| 2522 | 2523 |
| 2523 bool Isolate::use_crankshaft() const { | 2524 bool Isolate::use_crankshaft() const { |
| 2524 return FLAG_crankshaft && | 2525 return FLAG_crankshaft && |
| 2525 !serializer_enabled_ && | 2526 !serializer_enabled_ && |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2619 #ifdef DEBUG | 2620 #ifdef DEBUG |
| 2620 Map* root_array_map = get_initial_js_array_map(GetInitialFastElementsKind()); | 2621 Map* root_array_map = get_initial_js_array_map(GetInitialFastElementsKind()); |
| 2621 if (root_array_map == NULL) { | 2622 if (root_array_map == NULL) { |
| 2622 // Ignore the value of is_concat_spreadable during bootstrap. | 2623 // Ignore the value of is_concat_spreadable during bootstrap. |
| 2623 return !is_is_concat_spreadable_set; | 2624 return !is_is_concat_spreadable_set; |
| 2624 } | 2625 } |
| 2625 Handle<Object> array_prototype(array_function()->prototype(), this); | 2626 Handle<Object> array_prototype(array_function()->prototype(), this); |
| 2626 Handle<Symbol> key = factory()->is_concat_spreadable_symbol(); | 2627 Handle<Symbol> key = factory()->is_concat_spreadable_symbol(); |
| 2627 Handle<Object> value; | 2628 Handle<Object> value; |
| 2628 LookupIterator it(array_prototype, key); | 2629 LookupIterator it(array_prototype, key); |
| 2629 if (it.IsFound() && !JSReceiver::GetDataProperty(&it)->IsUndefined()) { | 2630 if (it.IsFound() && !JSReceiver::GetDataProperty(&it)->IsUndefined(this)) { |
| 2630 // TODO(cbruni): Currently we do not revert if we unset the | 2631 // TODO(cbruni): Currently we do not revert if we unset the |
| 2631 // @@isConcatSpreadable property on Array.prototype or Object.prototype | 2632 // @@isConcatSpreadable property on Array.prototype or Object.prototype |
| 2632 // hence the reverse implication doesn't hold. | 2633 // hence the reverse implication doesn't hold. |
| 2633 DCHECK(is_is_concat_spreadable_set); | 2634 DCHECK(is_is_concat_spreadable_set); |
| 2634 return false; | 2635 return false; |
| 2635 } | 2636 } |
| 2636 #endif // DEBUG | 2637 #endif // DEBUG |
| 2637 | 2638 |
| 2638 return !is_is_concat_spreadable_set; | 2639 return !is_is_concat_spreadable_set; |
| 2639 } | 2640 } |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2825 Handle<FixedArray> queue(heap()->microtask_queue(), this); | 2826 Handle<FixedArray> queue(heap()->microtask_queue(), this); |
| 2826 int num_tasks = pending_microtask_count(); | 2827 int num_tasks = pending_microtask_count(); |
| 2827 DCHECK(num_tasks <= queue->length()); | 2828 DCHECK(num_tasks <= queue->length()); |
| 2828 if (num_tasks == 0) { | 2829 if (num_tasks == 0) { |
| 2829 queue = factory()->NewFixedArray(8); | 2830 queue = factory()->NewFixedArray(8); |
| 2830 heap()->set_microtask_queue(*queue); | 2831 heap()->set_microtask_queue(*queue); |
| 2831 } else if (num_tasks == queue->length()) { | 2832 } else if (num_tasks == queue->length()) { |
| 2832 queue = factory()->CopyFixedArrayAndGrow(queue, num_tasks); | 2833 queue = factory()->CopyFixedArrayAndGrow(queue, num_tasks); |
| 2833 heap()->set_microtask_queue(*queue); | 2834 heap()->set_microtask_queue(*queue); |
| 2834 } | 2835 } |
| 2835 DCHECK(queue->get(num_tasks)->IsUndefined()); | 2836 DCHECK(queue->get(num_tasks)->IsUndefined(this)); |
| 2836 queue->set(num_tasks, *microtask); | 2837 queue->set(num_tasks, *microtask); |
| 2837 set_pending_microtask_count(num_tasks + 1); | 2838 set_pending_microtask_count(num_tasks + 1); |
| 2838 } | 2839 } |
| 2839 | 2840 |
| 2840 | 2841 |
| 2841 void Isolate::RunMicrotasks() { | 2842 void Isolate::RunMicrotasks() { |
| 2842 // Increase call depth to prevent recursive callbacks. | 2843 // Increase call depth to prevent recursive callbacks. |
| 2843 v8::Isolate::SuppressMicrotaskExecutionScope suppress( | 2844 v8::Isolate::SuppressMicrotaskExecutionScope suppress( |
| 2844 reinterpret_cast<v8::Isolate*>(this)); | 2845 reinterpret_cast<v8::Isolate*>(this)); |
| 2845 is_running_microtasks_ = true; | 2846 is_running_microtasks_ = true; |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3064 // Then check whether this scope intercepts. | 3065 // Then check whether this scope intercepts. |
| 3065 if ((flag & intercept_mask_)) { | 3066 if ((flag & intercept_mask_)) { |
| 3066 intercepted_flags_ |= flag; | 3067 intercepted_flags_ |= flag; |
| 3067 return true; | 3068 return true; |
| 3068 } | 3069 } |
| 3069 return false; | 3070 return false; |
| 3070 } | 3071 } |
| 3071 | 3072 |
| 3072 } // namespace internal | 3073 } // namespace internal |
| 3073 } // namespace v8 | 3074 } // namespace v8 |
| OLD | NEW |