Revision: 14182
Author: [email protected]
Date: Tue Apr 9 02:52:22 2013
Log: Merged r14171, r14175 into trunk branch.
Move context retrieval method around. Use delegation for implementation.
Fix slow path of JSON.stringifier when GC strikes.
[email protected]
BUG=
Review URL: https://codereview.chromium.org/13839008
http://code.google.com/p/v8/source/detail?r=14182
Modified:
/trunk/include/v8.h
/trunk/src/api.cc
/trunk/src/json-stringifier.h
/trunk/src/version.cc
/trunk/test/cctest/test-api.cc
/trunk/test/mjsunit/regress/regress-json-stringify-gc.js
=======================================
--- /trunk/include/v8.h Thu Apr 4 04:38:09 2013
+++ /trunk/include/v8.h Tue Apr 9 02:52:22 2013
@@ -3036,6 +3036,9 @@
*/
CpuProfiler* GetCpuProfiler();
+ /** Returns the context that is on the top of the stack. */
+ Local<Context> GetCurrentContext();
+
private:
Isolate();
Isolate(const Isolate&);
=======================================
--- /trunk/src/api.cc Thu Apr 4 04:38:09 2013
+++ /trunk/src/api.cc Tue Apr 9 02:52:22 2013
@@ -5811,6 +5811,15 @@
reinterpret_cast<i::Isolate*>(this)->cpu_profiler();
return reinterpret_cast<CpuProfiler*>(cpu_profiler);
}
+
+
+v8::Local<v8::Context> Isolate::GetCurrentContext() {
+ i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(this);
+ i::Handle<i::Object> current = internal_isolate->native_context();
+ if (current.is_null()) return Local<Context>();
+ i::Handle<i::Context> context = i::Handle<i::Context>::cast(current);
+ return Utils::ToLocal(context);
+}
void V8::SetGlobalGCPrologueCallback(GCCallback callback) {
=======================================
--- /trunk/src/json-stringifier.h Thu Apr 4 04:38:09 2013
+++ /trunk/src/json-stringifier.h Tue Apr 9 02:52:22 2013
@@ -295,19 +295,30 @@
return stringifier.Stringify(object);
}
- FlattenString(object);
- String::FlatContent flat = object->GetFlatContent();
- if (flat.IsAscii()) {
+ object = FlattenGetString(object);
+ ASSERT(object->IsFlat());
+ if (object->IsOneByteRepresentation()) {
+ Handle<String> result =
+ isolate->factory()->NewRawOneByteString(worst_case_length);
+ AssertNoAllocation no_alloc;
+ const uint8_t* start = object->IsSeqOneByteString()
+ ? SeqOneByteString::cast(*object)->GetChars()
+ : ExternalAsciiString::cast(*object)->GetChars();
return StringifyString_<SeqOneByteString>(
isolate,
- flat.ToOneByteVector(),
- isolate->factory()->NewRawOneByteString(worst_case_length));
+ Vector<const uint8_t>(start, object->length()),
+ result);
} else {
- ASSERT(flat.IsTwoByte());
+ Handle<String> result =
+ isolate->factory()->NewRawTwoByteString(worst_case_length);
+ AssertNoAllocation no_alloc;
+ const uc16* start = object->IsSeqTwoByteString()
+ ? SeqTwoByteString::cast(*object)->GetChars()
+ : ExternalTwoByteString::cast(*object)->GetChars();
return StringifyString_<SeqTwoByteString>(
isolate,
- flat.ToUC16Vector(),
- isolate->factory()->NewRawTwoByteString(worst_case_length));
+ Vector<const uc16>(start, object->length()),
+ result);
}
}
=======================================
--- /trunk/src/version.cc Thu Apr 4 04:38:09 2013
+++ /trunk/src/version.cc Tue Apr 9 02:52:22 2013
@@ -35,7 +35,7 @@
#define MAJOR_VERSION 3
#define MINOR_VERSION 17
#define BUILD_NUMBER 16
-#define PATCH_LEVEL 0
+#define PATCH_LEVEL 1
// Use 1 for candidates and 0 otherwise.
// (Boolean macro values are not supported by all preprocessors.)
#define IS_CANDIDATE_VERSION 0
=======================================
--- /trunk/test/cctest/test-api.cc Thu Apr 4 04:38:09 2013
+++ /trunk/test/cctest/test-api.cc Tue Apr 9 02:52:22 2013
@@ -13410,6 +13410,7 @@
static v8::Handle<Value> GetCallingContextCallback(const v8::Arguments&
args) {
ApiTestFuzzer::Fuzz();
CHECK(Context::GetCurrent() == calling_context0);
+ CHECK(args.GetIsolate()->GetCurrentContext() == calling_context0);
CHECK(Context::GetCalling() == calling_context1);
CHECK(Context::GetEntered() == calling_context2);
return v8::Integer::New(42);
=======================================
--- /trunk/test/mjsunit/regress/regress-json-stringify-gc.js Thu Dec 6
09:32:37 2012
+++ /trunk/test/mjsunit/regress/regress-json-stringify-gc.js Tue Apr 9
02:52:22 2013
@@ -39,3 +39,13 @@
json2 = JSON.stringify(a);
assertTrue(json1 == json2, "GC caused JSON.stringify to fail.");
+// Check that the slow path of JSON.stringify works correctly wrt GC.
+for (var i = 0; i < 100000; i++) {
+ var s = i.toString();
+ assertEquals('"' + s + '"', JSON.stringify(s, null, 0));
+}
+
+for (var i = 0; i < 100000; i++) {
+ var s = i.toString() + "\u2603";
+ assertEquals('"' + s + '"', JSON.stringify(s, null, 0));
+}
--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.