Revision: 3378 Author: [email protected] Date: Mon Nov 30 03:23:58 2009 Log: Merge revisions r3372 - r3374 to trunk
BUG=http://code.google.com/p/v8/issues/detail?id=528, http://crbug.com/23058 TEST=cctest/test-api/Bug528 Review URL: http://codereview.chromium.org/454001 http://code.google.com/p/v8/source/detail?r=3378 Modified: /branches/1.3/include/v8.h /branches/1.3/src/accessors.cc /branches/1.3/src/api.cc /branches/1.3/src/handles.cc /branches/1.3/src/messages.js /branches/1.3/src/objects-debug.cc /branches/1.3/src/objects.h /branches/1.3/src/version.cc /branches/1.3/test/cctest/test-api.cc /branches/1.3/test/cctest/test-debug.cc ======================================= --- /branches/1.3/include/v8.h Tue Nov 3 03:38:18 2009 +++ /branches/1.3/include/v8.h Mon Nov 30 03:23:58 2009 @@ -597,7 +597,7 @@ * with the debugger as this data object is only available through the * debugger API. */ - void SetData(Handle<Value> data); + void SetData(Handle<String> data); }; @@ -2632,7 +2632,7 @@ * with the debugger to provide additional information on the context through * the debugger API. */ - void SetData(Handle<Value> data); + void SetData(Handle<String> data); Local<Value> GetData(); /** ======================================= --- /branches/1.3/src/accessors.cc Mon Jun 29 01:26:34 2009 +++ /branches/1.3/src/accessors.cc Mon Nov 30 03:23:58 2009 @@ -315,7 +315,11 @@ HandleScope scope; Handle<Script> script(Script::cast(JSValue::cast(object)->value())); InitScriptLineEnds(script); - return script->line_ends(); + ASSERT(script->line_ends()->IsFixedArray()); + Handle<FixedArray> line_ends(FixedArray::cast(script->line_ends())); + Handle<FixedArray> copy = Factory::CopyFixedArray(line_ends); + Handle<JSArray> js_array = Factory::NewJSArrayWithElements(copy); + return *js_array; } ======================================= --- /branches/1.3/src/api.cc Tue Nov 3 03:38:18 2009 +++ /branches/1.3/src/api.cc Mon Nov 30 03:23:58 2009 @@ -450,7 +450,7 @@ } -void Context::SetData(v8::Handle<Value> data) { +void Context::SetData(v8::Handle<String> data) { if (IsDeadCheck("v8::Context::SetData()")) return; ENTER_V8; { @@ -1174,7 +1174,7 @@ } -void Script::SetData(v8::Handle<Value> data) { +void Script::SetData(v8::Handle<String> data) { ON_BAILOUT("v8::Script::SetData()", return); LOG_API("Script::SetData"); { ======================================= --- /branches/1.3/src/handles.cc Tue Nov 17 16:22:24 2009 +++ /branches/1.3/src/handles.cc Mon Nov 30 03:23:58 2009 @@ -417,8 +417,8 @@ if (!script->source()->IsString()) { ASSERT(script->source()->IsUndefined()); - script->set_line_ends(*(Factory::NewJSArray(0))); - ASSERT(script->line_ends()->IsJSArray()); + script->set_line_ends(*(Factory::NewFixedArray(0))); + ASSERT(script->line_ends()->IsFixedArray()); return; } @@ -451,9 +451,8 @@ } ASSERT(array_index == line_count); - Handle<JSArray> object = Factory::NewJSArrayWithElements(array); - script->set_line_ends(*object); - ASSERT(script->line_ends()->IsJSArray()); + script->set_line_ends(*array); + ASSERT(script->line_ends()->IsFixedArray()); } @@ -461,17 +460,17 @@ int GetScriptLineNumber(Handle<Script> script, int code_pos) { InitScriptLineEnds(script); AssertNoAllocation no_allocation; - JSArray* line_ends_array = JSArray::cast(script->line_ends()); - const int line_ends_len = (Smi::cast(line_ends_array->length()))->value(); + FixedArray* line_ends = FixedArray::cast(script->line_ends()); + const int line_ends_len = line_ends->length(); int line = -1; if (line_ends_len > 0 && - code_pos <= (Smi::cast(line_ends_array->GetElement(0)))->value()) { + code_pos <= (Smi::cast(line_ends->get(0)))->value()) { line = 0; } else { for (int i = 1; i < line_ends_len; ++i) { - if ((Smi::cast(line_ends_array->GetElement(i - 1)))->value() < code_pos && - code_pos <= (Smi::cast(line_ends_array->GetElement(i)))->value()) { + if ((Smi::cast(line_ends->get(i - 1)))->value() < code_pos && + code_pos <= (Smi::cast(line_ends->get(i)))->value()) { line = i; break; } ======================================= --- /branches/1.3/src/messages.js Wed Oct 7 02:00:33 2009 +++ /branches/1.3/src/messages.js Mon Nov 30 03:23:58 2009 @@ -238,14 +238,15 @@ Script.prototype.lineFromPosition = function(position) { var lower = 0; var upper = this.lineCount() - 1; + var line_ends = this.line_ends; // We'll never find invalid positions so bail right away. - if (position > this.line_ends[upper]) { + if (position > line_ends[upper]) { return -1; } // This means we don't have to safe-guard indexing line_ends[i - 1]. - if (position <= this.line_ends[0]) { + if (position <= line_ends[0]) { return 0; } @@ -253,9 +254,9 @@ while (upper >= 1) { var i = (lower + upper) >> 1; - if (position > this.line_ends[i]) { + if (position > line_ends[i]) { lower = i + 1; - } else if (position <= this.line_ends[i - 1]) { + } else if (position <= line_ends[i - 1]) { upper = i - 1; } else { return i; @@ -278,8 +279,9 @@ if (line == -1) return null; // Determine start, end and column. - var start = line == 0 ? 0 : this.line_ends[line - 1] + 1; - var end = this.line_ends[line]; + var line_ends = this.line_ends; + var start = line == 0 ? 0 : line_ends[line - 1] + 1; + var end = line_ends[line]; if (end > 0 && StringCharAt.call(this.source, end - 1) == '\r') end--; var column = position - start; @@ -368,8 +370,9 @@ return null; } - var from_position = from_line == 0 ? 0 : this.line_ends[from_line - 1] + 1; - var to_position = to_line == 0 ? 0 : this.line_ends[to_line - 1] + 1; + var line_ends = this.line_ends; + var from_position = from_line == 0 ? 0 : line_ends[from_line - 1] + 1; + var to_position = to_line == 0 ? 0 : line_ends[to_line - 1] + 1; // Return a source slice with line numbers re-adjusted to the resource. return new SourceSlice(this, from_line + this.line_offset, to_line + this.line_offset, @@ -391,8 +394,9 @@ } // Return the source line. - var start = line == 0 ? 0 : this.line_ends[line - 1] + 1; - var end = this.line_ends[line]; + var line_ends = this.line_ends; + var start = line == 0 ? 0 : line_ends[line - 1] + 1; + var end = line_ends[line]; return StringSubstring.call(this.source, start, end); } ======================================= --- /branches/1.3/src/objects-debug.cc Wed Nov 11 01:55:05 2009 +++ /branches/1.3/src/objects-debug.cc Mon Nov 30 03:23:58 2009 @@ -1170,6 +1170,20 @@ type()->ShortPrint(); PrintF("\n - id: "); id()->ShortPrint(); + PrintF("\n - data: "); + data()->ShortPrint(); + PrintF("\n - context data: "); + context_data()->ShortPrint(); + PrintF("\n - wrapper: "); + wrapper()->ShortPrint(); + PrintF("\n - compilation type: "); + compilation_type()->ShortPrint(); + PrintF("\n - line ends: "); + line_ends()->ShortPrint(); + PrintF("\n - eval from function: "); + eval_from_function()->ShortPrint(); + PrintF("\n - eval from instructions offset: "); + eval_from_instructions_offset()->ShortPrint(); PrintF("\n"); } ======================================= --- /branches/1.3/src/objects.h Fri Nov 13 00:04:17 2009 +++ /branches/1.3/src/objects.h Mon Nov 30 03:23:58 2009 @@ -3262,7 +3262,7 @@ // [compilation]: how the the script was compiled. DECL_ACCESSORS(compilation_type, Smi) - // [line_ends]: array of line ends positions. + // [line_ends]: FixedArray of line ends positions. DECL_ACCESSORS(line_ends, Object) // [eval_from_function]: for eval scripts the funcion from which eval was ======================================= --- /branches/1.3/src/version.cc Wed Nov 25 09:06:33 2009 +++ /branches/1.3/src/version.cc Mon Nov 30 03:23:58 2009 @@ -35,7 +35,7 @@ #define MAJOR_VERSION 1 #define MINOR_VERSION 3 #define BUILD_NUMBER 18 -#define PATCH_LEVEL 13 +#define PATCH_LEVEL 14 #define CANDIDATE_VERSION false // Define SONAME to have the SCons build the put a specific SONAME into the ======================================= --- /branches/1.3/test/cctest/test-api.cc Wed Nov 25 09:06:33 2009 +++ /branches/1.3/test/cctest/test-api.cc Mon Nov 30 03:23:58 2009 @@ -8712,3 +8712,89 @@ v8::String::Utf8Value value(try_catch.Exception()); CHECK_EQ(0, strcmp(*value, "Hey!")); } + + +static int GetGlobalObjectsCount() { + int count = 0; + v8::internal::HeapIterator it; + while (it.has_next()) { + v8::internal::HeapObject* object = it.next(); + if (object->IsJSGlobalObject()) { + count++; + } + } +#ifdef DEBUG + if (count > 0) v8::internal::Heap::TracePathToGlobal(); +#endif + return count; +} + + +TEST(Bug528) { + v8::V8::Initialize(); + + v8::HandleScope scope; + v8::Persistent<Context> context; + int gc_count; + + // Context-dependent context data creates reference from the compilation + // cache to the global object. + context = Context::New(); + { + v8::HandleScope scope; + + context->Enter(); + Local<v8::String> obj = v8::String::New(""); + context->SetData(obj); + CompileRun("1"); + context->Exit(); + } + context.Dispose(); + for (gc_count = 1; gc_count < 10; gc_count++) { + v8::internal::Heap::CollectAllGarbage(false); + if (GetGlobalObjectsCount() == 0) break; + } + CHECK_EQ(0, GetGlobalObjectsCount()); + CHECK_EQ(2, gc_count); + + // Eval in a function creates reference from the compilation cache to the + // global object. + context = Context::New(); + { + v8::HandleScope scope; + + context->Enter(); + CompileRun("function f(){eval('1')}; f()"); + context->Exit(); + } + context.Dispose(); + for (gc_count = 1; gc_count < 10; gc_count++) { + v8::internal::Heap::CollectAllGarbage(false); + if (GetGlobalObjectsCount() == 0) break; + } + CHECK_EQ(0, GetGlobalObjectsCount()); + CHECK_EQ(2, gc_count); + + // Looking up the line number for an exception creates reference from the + // compilation cache to the global object. + context = Context::New(); + { + v8::HandleScope scope; + + context->Enter(); + v8::TryCatch try_catch; + CompileRun("function f(){throw 1;}; f()"); + CHECK(try_catch.HasCaught()); + v8::Handle<v8::Message> message = try_catch.Message(); + CHECK(!message.IsEmpty()); + CHECK_EQ(1, message->GetLineNumber()); + context->Exit(); + } + context.Dispose(); + for (gc_count = 1; gc_count < 10; gc_count++) { + v8::internal::Heap::CollectAllGarbage(false); + if (GetGlobalObjectsCount() == 0) break; + } + CHECK_EQ(0, GetGlobalObjectsCount()); + CHECK_EQ(2, gc_count); +} ======================================= --- /branches/1.3/test/cctest/test-debug.cc Tue Nov 17 01:53:59 2009 +++ /branches/1.3/test/cctest/test-debug.cc Mon Nov 30 03:23:58 2009 @@ -4892,7 +4892,7 @@ v8::ScriptOrigin origin2 = v8::ScriptOrigin(v8::String::New("new name")); v8::Handle<v8::Script> script2 = v8::Script::Compile(script, &origin2); script2->Run(); - script2->SetData(data_obj); + script2->SetData(data_obj->ToString()); f = v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("f"))); f->Call(env->Global(), 0, NULL); CHECK_EQ(3, break_point_hit_count); @@ -4945,8 +4945,8 @@ CHECK(context_2->GetData()->IsUndefined()); // Set and check different data values. - v8::Handle<v8::Value> data_1 = v8::Number::New(1); - v8::Handle<v8::Value> data_2 = v8::String::New("2"); + v8::Handle<v8::String> data_1 = v8::String::New("1"); + v8::Handle<v8::String> data_2 = v8::String::New("2"); context_1->SetData(data_1); context_2->SetData(data_2); CHECK(context_1->GetData()->StrictEquals(data_1)); @@ -5109,7 +5109,7 @@ CHECK(context_1->GetData()->IsUndefined()); // Set and check a data value. - v8::Handle<v8::Value> data_1 = v8::Number::New(1); + v8::Handle<v8::String> data_1 = v8::String::New("1"); context_1->SetData(data_1); CHECK(context_1->GetData()->StrictEquals(data_1)); -- v8-dev mailing list [email protected] http://groups.google.com/group/v8-dev
