Reviewers: Michael Starzinger,
Description:
Avoid GC when printing shared function info.
[email protected]
BUG=
TEST=
Please review this at https://chromiumcodereview.appspot.com/10828048/
SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge
Affected files:
M src/objects-printer.cc
M test/cctest/test-heap.cc
Index: src/objects-printer.cc
diff --git a/src/objects-printer.cc b/src/objects-printer.cc
index
c35ed5e237cc1ab563cc9a329fcc0dea07c48f28..9bd7a75fda3da289a822161bbabb4908234b7996
100644
--- a/src/objects-printer.cc
+++ b/src/objects-printer.cc
@@ -794,7 +794,14 @@ void SharedFunctionInfo::SharedFunctionInfoPrint(FILE*
out) {
code()->ShortPrint(out);
if (HasSourceCode()) {
PrintF(out, "\n - source code = ");
- GetSourceCode()->ShortPrint(out);
+ String* source = String::cast(Script::cast(script())->source());
+ int start = start_position();
+ int length = end_position() - start;
+ SmartArrayPointer<char> source_string =
+ source->ToCString(DISALLOW_NULLS,
+ FAST_STRING_TRAVERSAL,
+ start, length, NULL);
+ PrintF(out, "%s", *source_string);
}
// Script files are often large, hard to read.
// PrintF(out, "\n - script =");
Index: test/cctest/test-heap.cc
diff --git a/test/cctest/test-heap.cc b/test/cctest/test-heap.cc
index
9229a97125e681b69a502a967a5e52c5f9d429af..2263de5e26ad925b9729489879ac86d8397058fd
100644
--- a/test/cctest/test-heap.cc
+++ b/test/cctest/test-heap.cc
@@ -1966,3 +1966,23 @@ TEST(Regress2237) {
HEAP->CollectAllGarbage(Heap::kNoGCFlags);
CHECK(SlicedString::cast(*slice)->parent()->IsSeqAsciiString());
}
+
+
+#ifdef OBJECT_PRINT
+TEST(PrintSharedFunctionInfo) {
+ InitializeVM();
+ v8::HandleScope scope;
+ const char* source = "f = function() { return 987654321; }\n"
+ "g = function() { return 123456789; }\n";
+ CompileRun(source);
+ Handle<String> g_symbol = FACTORY->LookupAsciiSymbol("g");
+ JSFunction* g_func;
+ MaybeObject* maybe_obj =
+ Isolate::Current()->context()->global()->GetProperty(*g_symbol);
+ CHECK(!maybe_obj->IsFailure());
+ CHECK(maybe_obj->To<JSFunction>(&g_func));
+
+ AssertNoAllocation no_alloc;
+ g_func->shared()->PrintLn();
+}
+#endif // OBJECT_PRINT
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev