OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 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/v8.h" | 5 #include "src/v8.h" |
6 | 6 |
7 #include "src/accessors.h" | 7 #include "src/accessors.h" |
8 #include "src/arguments.h" | 8 #include "src/arguments.h" |
9 #include "src/compiler.h" | 9 #include "src/compiler.h" |
10 #include "src/debug.h" | 10 #include "src/debug.h" |
(...skipping 2165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2176 | 2176 |
2177 | 2177 |
2178 static bool IsPositionAlignmentCodeCorrect(int alignment) { | 2178 static bool IsPositionAlignmentCodeCorrect(int alignment) { |
2179 return alignment == STATEMENT_ALIGNED || alignment == BREAK_POSITION_ALIGNED; | 2179 return alignment == STATEMENT_ALIGNED || alignment == BREAK_POSITION_ALIGNED; |
2180 } | 2180 } |
2181 | 2181 |
2182 | 2182 |
2183 RUNTIME_FUNCTION(Runtime_GetBreakLocations) { | 2183 RUNTIME_FUNCTION(Runtime_GetBreakLocations) { |
2184 HandleScope scope(isolate); | 2184 HandleScope scope(isolate); |
2185 DCHECK(args.length() == 2); | 2185 DCHECK(args.length() == 2); |
2186 | 2186 RUNTIME_ASSERT(isolate->debug()->is_active()); |
2187 CONVERT_ARG_HANDLE_CHECKED(JSFunction, fun, 0); | 2187 CONVERT_ARG_HANDLE_CHECKED(JSFunction, fun, 0); |
2188 CONVERT_NUMBER_CHECKED(int32_t, statement_aligned_code, Int32, args[1]); | 2188 CONVERT_NUMBER_CHECKED(int32_t, statement_aligned_code, Int32, args[1]); |
2189 | 2189 |
2190 if (!IsPositionAlignmentCodeCorrect(statement_aligned_code)) { | 2190 if (!IsPositionAlignmentCodeCorrect(statement_aligned_code)) { |
2191 return isolate->ThrowIllegalOperation(); | 2191 return isolate->ThrowIllegalOperation(); |
2192 } | 2192 } |
2193 BreakPositionAlignment alignment = | 2193 BreakPositionAlignment alignment = |
2194 static_cast<BreakPositionAlignment>(statement_aligned_code); | 2194 static_cast<BreakPositionAlignment>(statement_aligned_code); |
2195 | 2195 |
2196 Handle<SharedFunctionInfo> shared(fun->shared()); | 2196 Handle<SharedFunctionInfo> shared(fun->shared()); |
2197 // Find the number of break points | 2197 // Find the number of break points |
2198 Handle<Object> break_locations = | 2198 Handle<Object> break_locations = |
2199 Debug::GetSourceBreakLocations(shared, alignment); | 2199 Debug::GetSourceBreakLocations(shared, alignment); |
2200 if (break_locations->IsUndefined()) return isolate->heap()->undefined_value(); | 2200 if (break_locations->IsUndefined()) return isolate->heap()->undefined_value(); |
2201 // Return array as JS array | 2201 // Return array as JS array |
2202 return *isolate->factory()->NewJSArrayWithElements( | 2202 return *isolate->factory()->NewJSArrayWithElements( |
2203 Handle<FixedArray>::cast(break_locations)); | 2203 Handle<FixedArray>::cast(break_locations)); |
2204 } | 2204 } |
2205 | 2205 |
2206 | 2206 |
2207 // Set a break point in a function. | 2207 // Set a break point in a function. |
2208 // args[0]: function | 2208 // args[0]: function |
2209 // args[1]: number: break source position (within the function source) | 2209 // args[1]: number: break source position (within the function source) |
2210 // args[2]: number: break point object | 2210 // args[2]: number: break point object |
2211 RUNTIME_FUNCTION(Runtime_SetFunctionBreakPoint) { | 2211 RUNTIME_FUNCTION(Runtime_SetFunctionBreakPoint) { |
2212 HandleScope scope(isolate); | 2212 HandleScope scope(isolate); |
2213 DCHECK(args.length() == 3); | 2213 DCHECK(args.length() == 3); |
| 2214 RUNTIME_ASSERT(isolate->debug()->is_active()); |
2214 CONVERT_ARG_HANDLE_CHECKED(JSFunction, function, 0); | 2215 CONVERT_ARG_HANDLE_CHECKED(JSFunction, function, 0); |
2215 CONVERT_NUMBER_CHECKED(int32_t, source_position, Int32, args[1]); | 2216 CONVERT_NUMBER_CHECKED(int32_t, source_position, Int32, args[1]); |
2216 RUNTIME_ASSERT(source_position >= function->shared()->start_position() && | 2217 RUNTIME_ASSERT(source_position >= function->shared()->start_position() && |
2217 source_position <= function->shared()->end_position()); | 2218 source_position <= function->shared()->end_position()); |
2218 CONVERT_ARG_HANDLE_CHECKED(Object, break_point_object_arg, 2); | 2219 CONVERT_ARG_HANDLE_CHECKED(Object, break_point_object_arg, 2); |
2219 | 2220 |
2220 // Set break point. | 2221 // Set break point. |
2221 RUNTIME_ASSERT(isolate->debug()->SetBreakPoint( | 2222 RUNTIME_ASSERT(isolate->debug()->SetBreakPoint( |
2222 function, break_point_object_arg, &source_position)); | 2223 function, break_point_object_arg, &source_position)); |
2223 | 2224 |
2224 return Smi::FromInt(source_position); | 2225 return Smi::FromInt(source_position); |
2225 } | 2226 } |
2226 | 2227 |
2227 | 2228 |
2228 // Changes the state of a break point in a script and returns source position | 2229 // Changes the state of a break point in a script and returns source position |
2229 // where break point was set. NOTE: Regarding performance see the NOTE for | 2230 // where break point was set. NOTE: Regarding performance see the NOTE for |
2230 // GetScriptFromScriptData. | 2231 // GetScriptFromScriptData. |
2231 // args[0]: script to set break point in | 2232 // args[0]: script to set break point in |
2232 // args[1]: number: break source position (within the script source) | 2233 // args[1]: number: break source position (within the script source) |
2233 // args[2]: number, breakpoint position alignment | 2234 // args[2]: number, breakpoint position alignment |
2234 // args[3]: number: break point object | 2235 // args[3]: number: break point object |
2235 RUNTIME_FUNCTION(Runtime_SetScriptBreakPoint) { | 2236 RUNTIME_FUNCTION(Runtime_SetScriptBreakPoint) { |
2236 HandleScope scope(isolate); | 2237 HandleScope scope(isolate); |
2237 DCHECK(args.length() == 4); | 2238 DCHECK(args.length() == 4); |
| 2239 RUNTIME_ASSERT(isolate->debug()->is_active()); |
2238 CONVERT_ARG_HANDLE_CHECKED(JSValue, wrapper, 0); | 2240 CONVERT_ARG_HANDLE_CHECKED(JSValue, wrapper, 0); |
2239 CONVERT_NUMBER_CHECKED(int32_t, source_position, Int32, args[1]); | 2241 CONVERT_NUMBER_CHECKED(int32_t, source_position, Int32, args[1]); |
2240 RUNTIME_ASSERT(source_position >= 0); | 2242 RUNTIME_ASSERT(source_position >= 0); |
2241 CONVERT_NUMBER_CHECKED(int32_t, statement_aligned_code, Int32, args[2]); | 2243 CONVERT_NUMBER_CHECKED(int32_t, statement_aligned_code, Int32, args[2]); |
2242 CONVERT_ARG_HANDLE_CHECKED(Object, break_point_object_arg, 3); | 2244 CONVERT_ARG_HANDLE_CHECKED(Object, break_point_object_arg, 3); |
2243 | 2245 |
2244 if (!IsPositionAlignmentCodeCorrect(statement_aligned_code)) { | 2246 if (!IsPositionAlignmentCodeCorrect(statement_aligned_code)) { |
2245 return isolate->ThrowIllegalOperation(); | 2247 return isolate->ThrowIllegalOperation(); |
2246 } | 2248 } |
2247 BreakPositionAlignment alignment = | 2249 BreakPositionAlignment alignment = |
(...skipping 11 matching lines...) Expand all Loading... |
2259 | 2261 |
2260 return Smi::FromInt(source_position); | 2262 return Smi::FromInt(source_position); |
2261 } | 2263 } |
2262 | 2264 |
2263 | 2265 |
2264 // Clear a break point | 2266 // Clear a break point |
2265 // args[0]: number: break point object | 2267 // args[0]: number: break point object |
2266 RUNTIME_FUNCTION(Runtime_ClearBreakPoint) { | 2268 RUNTIME_FUNCTION(Runtime_ClearBreakPoint) { |
2267 HandleScope scope(isolate); | 2269 HandleScope scope(isolate); |
2268 DCHECK(args.length() == 1); | 2270 DCHECK(args.length() == 1); |
| 2271 RUNTIME_ASSERT(isolate->debug()->is_active()); |
2269 CONVERT_ARG_HANDLE_CHECKED(Object, break_point_object_arg, 0); | 2272 CONVERT_ARG_HANDLE_CHECKED(Object, break_point_object_arg, 0); |
2270 | 2273 |
2271 // Clear break point. | 2274 // Clear break point. |
2272 isolate->debug()->ClearBreakPoint(break_point_object_arg); | 2275 isolate->debug()->ClearBreakPoint(break_point_object_arg); |
2273 | 2276 |
2274 return isolate->heap()->undefined_value(); | 2277 return isolate->heap()->undefined_value(); |
2275 } | 2278 } |
2276 | 2279 |
2277 | 2280 |
2278 // Change the state of break on exceptions. | 2281 // Change the state of break on exceptions. |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2356 isolate->debug()->PrepareStep(static_cast<StepAction>(step_action), | 2359 isolate->debug()->PrepareStep(static_cast<StepAction>(step_action), |
2357 step_count, frame_id); | 2360 step_count, frame_id); |
2358 return isolate->heap()->undefined_value(); | 2361 return isolate->heap()->undefined_value(); |
2359 } | 2362 } |
2360 | 2363 |
2361 | 2364 |
2362 // Clear all stepping set by PrepareStep. | 2365 // Clear all stepping set by PrepareStep. |
2363 RUNTIME_FUNCTION(Runtime_ClearStepping) { | 2366 RUNTIME_FUNCTION(Runtime_ClearStepping) { |
2364 HandleScope scope(isolate); | 2367 HandleScope scope(isolate); |
2365 DCHECK(args.length() == 0); | 2368 DCHECK(args.length() == 0); |
| 2369 RUNTIME_ASSERT(isolate->debug()->is_active()); |
2366 isolate->debug()->ClearStepping(); | 2370 isolate->debug()->ClearStepping(); |
2367 return isolate->heap()->undefined_value(); | 2371 return isolate->heap()->undefined_value(); |
2368 } | 2372 } |
2369 | 2373 |
2370 | 2374 |
2371 // Helper function to find or create the arguments object for | 2375 // Helper function to find or create the arguments object for |
2372 // Runtime_DebugEvaluate. | 2376 // Runtime_DebugEvaluate. |
2373 static void MaterializeArgumentsObject(Isolate* isolate, | 2377 static void MaterializeArgumentsObject(Isolate* isolate, |
2374 Handle<JSObject> target, | 2378 Handle<JSObject> target, |
2375 Handle<JSFunction> function) { | 2379 Handle<JSFunction> function) { |
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2702 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 2706 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
2703 isolate, result, DebugEvaluate(isolate, outer_info, context, | 2707 isolate, result, DebugEvaluate(isolate, outer_info, context, |
2704 context_extension, receiver, source)); | 2708 context_extension, receiver, source)); |
2705 return *result; | 2709 return *result; |
2706 } | 2710 } |
2707 | 2711 |
2708 | 2712 |
2709 RUNTIME_FUNCTION(Runtime_DebugGetLoadedScripts) { | 2713 RUNTIME_FUNCTION(Runtime_DebugGetLoadedScripts) { |
2710 HandleScope scope(isolate); | 2714 HandleScope scope(isolate); |
2711 DCHECK(args.length() == 0); | 2715 DCHECK(args.length() == 0); |
| 2716 RUNTIME_ASSERT(isolate->debug()->is_active()); |
2712 | 2717 |
2713 Handle<FixedArray> instances; | 2718 Handle<FixedArray> instances; |
2714 { | 2719 { |
2715 DebugScope debug_scope(isolate->debug()); | 2720 DebugScope debug_scope(isolate->debug()); |
2716 if (debug_scope.failed()) { | 2721 if (debug_scope.failed()) { |
2717 DCHECK(isolate->has_pending_exception()); | 2722 DCHECK(isolate->has_pending_exception()); |
2718 return isolate->heap()->exception(); | 2723 return isolate->heap()->exception(); |
2719 } | 2724 } |
2720 // Fill the script objects. | 2725 // Fill the script objects. |
2721 instances = isolate->debug()->GetLoadedScripts(); | 2726 instances = isolate->debug()->GetLoadedScripts(); |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2969 return f->shared()->inferred_name(); | 2974 return f->shared()->inferred_name(); |
2970 } | 2975 } |
2971 | 2976 |
2972 | 2977 |
2973 // A testing entry. Returns statement position which is the closest to | 2978 // A testing entry. Returns statement position which is the closest to |
2974 // source_position. | 2979 // source_position. |
2975 RUNTIME_FUNCTION(Runtime_GetFunctionCodePositionFromSource) { | 2980 RUNTIME_FUNCTION(Runtime_GetFunctionCodePositionFromSource) { |
2976 HandleScope scope(isolate); | 2981 HandleScope scope(isolate); |
2977 CHECK(isolate->debug()->live_edit_enabled()); | 2982 CHECK(isolate->debug()->live_edit_enabled()); |
2978 DCHECK(args.length() == 2); | 2983 DCHECK(args.length() == 2); |
| 2984 RUNTIME_ASSERT(isolate->debug()->is_active()); |
2979 CONVERT_ARG_HANDLE_CHECKED(JSFunction, function, 0); | 2985 CONVERT_ARG_HANDLE_CHECKED(JSFunction, function, 0); |
2980 CONVERT_NUMBER_CHECKED(int32_t, source_position, Int32, args[1]); | 2986 CONVERT_NUMBER_CHECKED(int32_t, source_position, Int32, args[1]); |
2981 | 2987 |
2982 Handle<Code> code(function->code(), isolate); | 2988 Handle<Code> code(function->code(), isolate); |
2983 | 2989 |
2984 if (code->kind() != Code::FUNCTION && | 2990 if (code->kind() != Code::FUNCTION && |
2985 code->kind() != Code::OPTIMIZED_FUNCTION) { | 2991 code->kind() != Code::OPTIMIZED_FUNCTION) { |
2986 return isolate->heap()->undefined_value(); | 2992 return isolate->heap()->undefined_value(); |
2987 } | 2993 } |
2988 | 2994 |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3110 callback->IsJSFunction() && | 3116 callback->IsJSFunction() && |
3111 (!JSFunction::cast(callback)->IsBuiltin() || | 3117 (!JSFunction::cast(callback)->IsBuiltin() || |
3112 JSFunction::cast(callback)->shared()->bound())); | 3118 JSFunction::cast(callback)->shared()->bound())); |
3113 } | 3119 } |
3114 | 3120 |
3115 | 3121 |
3116 // Set one shot breakpoints for the callback function that is passed to a | 3122 // Set one shot breakpoints for the callback function that is passed to a |
3117 // built-in function such as Array.forEach to enable stepping into the callback. | 3123 // built-in function such as Array.forEach to enable stepping into the callback. |
3118 RUNTIME_FUNCTION(Runtime_DebugPrepareStepInIfStepping) { | 3124 RUNTIME_FUNCTION(Runtime_DebugPrepareStepInIfStepping) { |
3119 DCHECK(args.length() == 1); | 3125 DCHECK(args.length() == 1); |
| 3126 RUNTIME_ASSERT(isolate->debug()->is_active()); |
| 3127 |
3120 Debug* debug = isolate->debug(); | 3128 Debug* debug = isolate->debug(); |
3121 if (!debug->IsStepping()) return isolate->heap()->undefined_value(); | 3129 if (!debug->IsStepping()) return isolate->heap()->undefined_value(); |
3122 | 3130 |
3123 HandleScope scope(isolate); | 3131 HandleScope scope(isolate); |
3124 CONVERT_ARG_HANDLE_CHECKED(Object, object, 0); | 3132 CONVERT_ARG_HANDLE_CHECKED(Object, object, 0); |
3125 RUNTIME_ASSERT(object->IsJSFunction() || object->IsJSGeneratorObject()); | 3133 RUNTIME_ASSERT(object->IsJSFunction() || object->IsJSGeneratorObject()); |
3126 Handle<JSFunction> fun; | 3134 Handle<JSFunction> fun; |
3127 if (object->IsJSFunction()) { | 3135 if (object->IsJSFunction()) { |
3128 fun = Handle<JSFunction>::cast(object); | 3136 fun = Handle<JSFunction>::cast(object); |
3129 } else { | 3137 } else { |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3180 return Smi::FromInt(isolate->debug()->is_active()); | 3188 return Smi::FromInt(isolate->debug()->is_active()); |
3181 } | 3189 } |
3182 | 3190 |
3183 | 3191 |
3184 RUNTIME_FUNCTION(Runtime_DebugBreakInOptimizedCode) { | 3192 RUNTIME_FUNCTION(Runtime_DebugBreakInOptimizedCode) { |
3185 UNIMPLEMENTED(); | 3193 UNIMPLEMENTED(); |
3186 return NULL; | 3194 return NULL; |
3187 } | 3195 } |
3188 } // namespace internal | 3196 } // namespace internal |
3189 } // namespace v8 | 3197 } // namespace v8 |
OLD | NEW |