Reviewers: danno,
Description:
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=
Please review this at https://codereview.chromium.org/13839008/
SVN Base: https://v8.googlecode.com/svn/trunk
Affected files:
M include/v8.h
M src/api.cc
M src/json-stringifier.h
M src/version.cc
M test/cctest/test-api.cc
M test/mjsunit/regress/regress-json-stringify-gc.js
Index: include/v8.h
diff --git a/include/v8.h b/include/v8.h
index
9adb1c041cf20bd2ed12d7a04dfe07c53cd1712b..3961503348ada2246c98243d8af7495cb1b19520
100644
--- a/include/v8.h
+++ b/include/v8.h
@@ -3036,6 +3036,9 @@ class V8EXPORT Isolate {
*/
CpuProfiler* GetCpuProfiler();
+ /** Returns the context that is on the top of the stack. */
+ Local<Context> GetCurrentContext();
+
private:
Isolate();
Isolate(const Isolate&);
Index: src/api.cc
diff --git a/src/api.cc b/src/api.cc
index
65663ba5c66c6dfcb1e210d31949fa59ed642d71..178eeabe02a3138dd7285fdaa3f3737ba62b9e2a
100644
--- a/src/api.cc
+++ b/src/api.cc
@@ -5813,6 +5813,15 @@ CpuProfiler* Isolate::GetCpuProfiler() {
}
+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) {
i::Isolate* isolate = i::Isolate::Current();
if (IsDeadCheck(isolate, "v8::V8::SetGlobalGCPrologueCallback()"))
return;
Index: src/json-stringifier.h
diff --git a/src/json-stringifier.h b/src/json-stringifier.h
index
bcdd64ce7643e57bb3732c51cfe2fb5d9a7b3217..a154a4e99a3db613a6ddf555cec9a1762773fff4
100644
--- a/src/json-stringifier.h
+++ b/src/json-stringifier.h
@@ -295,19 +295,30 @@ MaybeObject*
BasicJsonStringifier::StringifyString(Isolate* isolate,
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);
}
}
Index: src/version.cc
diff --git a/src/version.cc b/src/version.cc
index
64ed98d4666aedaa8ec58b7be4f9368a59eae627..c7312eb9d1d077107fbb03a7e571f1983e2e8b7a
100644
--- a/src/version.cc
+++ b/src/version.cc
@@ -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
Index: test/cctest/test-api.cc
diff --git a/test/cctest/test-api.cc b/test/cctest/test-api.cc
index
a9780f0332644af77e4ee147747e1931d3ba9362..1e789f30da847221395b9489802aacc8375187be
100644
--- a/test/cctest/test-api.cc
+++ b/test/cctest/test-api.cc
@@ -13410,6 +13410,7 @@ v8::Persistent<Context> calling_context2;
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);
Index: test/mjsunit/regress/regress-json-stringify-gc.js
diff --git a/test/mjsunit/regress/regress-json-stringify-gc.js
b/test/mjsunit/regress/regress-json-stringify-gc.js
index
c0a71bf4a1e1b2ea85486c0aade362cee62f9fb0..4b355ae1acbad7e0ac3687b2a2c48ba70be2e753
100644
--- a/test/mjsunit/regress/regress-json-stringify-gc.js
+++ b/test/mjsunit/regress/regress-json-stringify-gc.js
@@ -39,3 +39,13 @@ json1 = JSON.stringify(a);
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.