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

Side by Side Diff: test/cctest/test-debug.cc

Issue 1994973002: Revert of Refactor script position calculation (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: 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
« no previous file with comments | « test/cctest/test-api.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 TEST(DebugScriptLineEndsAreAscending) { 6084
6085 TEST(DebugGetLoadedScripts) {
6085 DebugLocalContext env; 6086 DebugLocalContext env;
6086 v8::Isolate* isolate = env->GetIsolate(); 6087 v8::HandleScope scope(env->GetIsolate());
6087 v8::HandleScope scope(isolate);
6088 env.ExposeDebug(); 6088 env.ExposeDebug();
6089 6089
6090 // Compile a test script. 6090 v8::Local<v8::Context> context = env.context();
6091 v8::Local<v8::String> script = v8_str(isolate, 6091 EmptyExternalStringResource source_ext_str;
6092 "function f() {\n" 6092 v8::Local<v8::String> source =
6093 " debugger;\n" 6093 v8::String::NewExternalTwoByte(env->GetIsolate(), &source_ext_str)
6094 "}\n"); 6094 .ToLocalChecked();
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);
6095 6101
6096 v8::ScriptOrigin origin1 = v8::ScriptOrigin(v8_str(isolate, "name")); 6102 bool allow_natives_syntax = i::FLAG_allow_natives_syntax;
6097 v8::Local<v8::Script> script1 = 6103 i::FLAG_allow_natives_syntax = true;
6098 v8::Script::Compile(env.context(), script, &origin1).ToLocalChecked(); 6104 EnableDebugger(env->GetIsolate());
6099 USE(script1); 6105 v8::MaybeLocal<v8::Value> result =
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;
6100 6123
6101 Handle<v8::internal::FixedArray> instances; 6124 // Some scripts are retrieved - at least the number of native scripts.
6102 { 6125 CHECK_GT(env->Global()
6103 v8::internal::Debug* debug = CcTest::i_isolate()->debug(); 6126 ->Get(context, v8_str(env->GetIsolate(), "count"))
6104 v8::internal::DebugScope debug_scope(debug); 6127 .ToLocalChecked()
6105 CHECK(!debug_scope.failed()); 6128 ->Int32Value(context)
6106 instances = debug->GetLoadedScripts(); 6129 .FromJust(),
6107 } 6130 8);
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 }
6126 } 6131 }
6127 6132
6128 6133
6129 // Test script break points set on lines. 6134 // Test script break points set on lines.
6130 TEST(ScriptNameAndData) { 6135 TEST(ScriptNameAndData) {
6131 DebugLocalContext env; 6136 DebugLocalContext env;
6132 v8::HandleScope scope(env->GetIsolate()); 6137 v8::HandleScope scope(env->GetIsolate());
6133 env.ExposeDebug(); 6138 env.ExposeDebug();
6134 6139
6135 // Create functions for retrieving script name and data for the function on 6140 // Create functions for retrieving script name and data for the function on
(...skipping 2039 matching lines...) Expand 10 before | Expand all | Expand 10 after
8175 "function foo() {\n" 8180 "function foo() {\n"
8176 " try { throw new Error(); } catch (e) {}\n" 8181 " try { throw new Error(); } catch (e) {}\n"
8177 "}\n" 8182 "}\n"
8178 "debugger;\n" 8183 "debugger;\n"
8179 "foo();\n" 8184 "foo();\n"
8180 "foo();\n"); 8185 "foo();\n");
8181 8186
8182 v8::Debug::SetDebugEventListener(env->GetIsolate(), nullptr); 8187 v8::Debug::SetDebugEventListener(env->GetIsolate(), nullptr);
8183 CHECK_EQ(break_point_hit_count, 4); 8188 CHECK_EQ(break_point_hit_count, 4);
8184 } 8189 }
OLDNEW
« no previous file with comments | « test/cctest/test-api.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698