OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 6063 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6074 class EmptyExternalStringResource : public v8::String::ExternalStringResource { | 6074 class EmptyExternalStringResource : public v8::String::ExternalStringResource { |
6075 public: | 6075 public: |
6076 EmptyExternalStringResource() { empty_[0] = 0; } | 6076 EmptyExternalStringResource() { empty_[0] = 0; } |
6077 virtual ~EmptyExternalStringResource() {} | 6077 virtual ~EmptyExternalStringResource() {} |
6078 virtual size_t length() const { return empty_.length(); } | 6078 virtual size_t length() const { return empty_.length(); } |
6079 virtual const uint16_t* data() const { return empty_.start(); } | 6079 virtual const uint16_t* data() const { return empty_.start(); } |
6080 private: | 6080 private: |
6081 ::v8::internal::EmbeddedVector<uint16_t, 1> empty_; | 6081 ::v8::internal::EmbeddedVector<uint16_t, 1> empty_; |
6082 }; | 6082 }; |
6083 | 6083 |
6084 | 6084 TEST(DebugScriptLineEndsAreAscending) { |
6085 TEST(DebugGetLoadedScripts) { | |
6086 DebugLocalContext env; | 6085 DebugLocalContext env; |
6087 v8::HandleScope scope(env->GetIsolate()); | 6086 v8::Isolate* isolate = env->GetIsolate(); |
| 6087 v8::HandleScope scope(isolate); |
6088 env.ExposeDebug(); | 6088 env.ExposeDebug(); |
6089 | 6089 |
6090 v8::Local<v8::Context> context = env.context(); | 6090 // Compile a test script. |
6091 EmptyExternalStringResource source_ext_str; | 6091 v8::Local<v8::String> script = v8_str(isolate, |
6092 v8::Local<v8::String> source = | 6092 "function f() {\n" |
6093 v8::String::NewExternalTwoByte(env->GetIsolate(), &source_ext_str) | 6093 " debugger;\n" |
6094 .ToLocalChecked(); | 6094 "}\n"); |
6095 CHECK(v8::Script::Compile(context, source).IsEmpty()); | |
6096 Handle<i::ExternalTwoByteString> i_source( | |
6097 i::ExternalTwoByteString::cast(*v8::Utils::OpenHandle(*source))); | |
6098 // This situation can happen if source was an external string disposed | |
6099 // by its owner. | |
6100 i_source->set_resource(0); | |
6101 | 6095 |
6102 bool allow_natives_syntax = i::FLAG_allow_natives_syntax; | 6096 v8::ScriptOrigin origin1 = v8::ScriptOrigin(v8_str(isolate, "name")); |
6103 i::FLAG_allow_natives_syntax = true; | 6097 v8::Local<v8::Script> script1 = |
6104 EnableDebugger(env->GetIsolate()); | 6098 v8::Script::Compile(env.context(), script, &origin1).ToLocalChecked(); |
6105 v8::MaybeLocal<v8::Value> result = | 6099 USE(script1); |
6106 CompileRun(env.context(), | |
6107 "var scripts = %DebugGetLoadedScripts();" | |
6108 "var count = scripts.length;" | |
6109 "for (var i = 0; i < count; ++i) {" | |
6110 " var lines = scripts[i].lineCount();" | |
6111 " if (lines < 1) throw 'lineCount';" | |
6112 " var last = -1;" | |
6113 " for (var j = 0; j < lines; ++j) {" | |
6114 " var end = scripts[i].lineEnd(j);" | |
6115 " if (last >= end) throw 'lineEnd';" | |
6116 " last = end;" | |
6117 " }" | |
6118 "}"); | |
6119 CHECK(!result.IsEmpty()); | |
6120 DisableDebugger(env->GetIsolate()); | |
6121 // Must not crash while accessing line_ends. | |
6122 i::FLAG_allow_natives_syntax = allow_natives_syntax; | |
6123 | 6100 |
6124 // Some scripts are retrieved - at least the number of native scripts. | 6101 Handle<v8::internal::FixedArray> instances; |
6125 CHECK_GT(env->Global() | 6102 { |
6126 ->Get(context, v8_str(env->GetIsolate(), "count")) | 6103 v8::internal::Debug* debug = CcTest::i_isolate()->debug(); |
6127 .ToLocalChecked() | 6104 v8::internal::DebugScope debug_scope(debug); |
6128 ->Int32Value(context) | 6105 CHECK(!debug_scope.failed()); |
6129 .FromJust(), | 6106 instances = debug->GetLoadedScripts(); |
6130 8); | 6107 } |
| 6108 |
| 6109 CHECK_GT(instances->length(), 0); |
| 6110 for (int i = 0; i < instances->length(); i++) { |
| 6111 Handle<v8::internal::Script> script = Handle<v8::internal::Script>( |
| 6112 v8::internal::Script::cast(instances->get(i))); |
| 6113 |
| 6114 v8::internal::Script::InitLineEnds(script); |
| 6115 v8::internal::FixedArray* ends = |
| 6116 v8::internal::FixedArray::cast(script->line_ends()); |
| 6117 CHECK_GT(ends->length(), 0); |
| 6118 |
| 6119 int prev_end = -1; |
| 6120 for (int j = 0; j < ends->length(); j++) { |
| 6121 const int curr_end = v8::internal::Smi::cast(ends->get(j))->value(); |
| 6122 CHECK_GT(curr_end, prev_end); |
| 6123 prev_end = curr_end; |
| 6124 } |
| 6125 } |
6131 } | 6126 } |
6132 | 6127 |
6133 | 6128 |
6134 // Test script break points set on lines. | 6129 // Test script break points set on lines. |
6135 TEST(ScriptNameAndData) { | 6130 TEST(ScriptNameAndData) { |
6136 DebugLocalContext env; | 6131 DebugLocalContext env; |
6137 v8::HandleScope scope(env->GetIsolate()); | 6132 v8::HandleScope scope(env->GetIsolate()); |
6138 env.ExposeDebug(); | 6133 env.ExposeDebug(); |
6139 | 6134 |
6140 // Create functions for retrieving script name and data for the function on | 6135 // Create functions for retrieving script name and data for the function on |
(...skipping 2039 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8180 "function foo() {\n" | 8175 "function foo() {\n" |
8181 " try { throw new Error(); } catch (e) {}\n" | 8176 " try { throw new Error(); } catch (e) {}\n" |
8182 "}\n" | 8177 "}\n" |
8183 "debugger;\n" | 8178 "debugger;\n" |
8184 "foo();\n" | 8179 "foo();\n" |
8185 "foo();\n"); | 8180 "foo();\n"); |
8186 | 8181 |
8187 v8::Debug::SetDebugEventListener(env->GetIsolate(), nullptr); | 8182 v8::Debug::SetDebugEventListener(env->GetIsolate(), nullptr); |
8188 CHECK_EQ(break_point_hit_count, 4); | 8183 CHECK_EQ(break_point_hit_count, 4); |
8189 } | 8184 } |
OLD | NEW |