Reviewers: Hannes Payer,
Description:
Check that ExternalString objects get aligned resources.
[email protected]
Please review this at https://codereview.chromium.org/20305004/
SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge
Affected files:
M src/api.cc
Index: src/api.cc
diff --git a/src/api.cc b/src/api.cc
index
c93b23c47105f70a630af1cc6cdf3548dde88712..cc5a3044b2ff1a8bc2e80f32e9a300ba27d7eedb
100644
--- a/src/api.cc
+++ b/src/api.cc
@@ -780,8 +780,8 @@ static void* DecodeSmiToAligned(i::Object* value, const
char* location) {
}
-static i::Smi* EncodeAlignedAsSmi(void* value, const char* location) {
- i::Smi* smi = reinterpret_cast<i::Smi*>(value);
+static i::Smi* EncodeAlignedAsSmi(const void* value, const char* location)
{
+ i::Smi* smi = const_cast<i::Smi*>(reinterpret_cast<const
i::Smi*>(value));
ApiCheck(smi->IsSmi(), location, "Pointer is not aligned");
return smi;
}
@@ -5938,6 +5938,10 @@ Local<String> v8::String::NewExternal(
LOG_API(isolate, "String::NewExternal");
ENTER_V8(isolate);
CHECK(resource && resource->data());
+ // Resource pointers need to look like Smis since ExternalString objects
+ // are sometimes put into old pointer space (see
i::String::MakeExternal).
+ CHECK(EncodeAlignedAsSmi(resource, "v8::String::NewExternal()"));
+ CHECK(EncodeAlignedAsSmi(resource->data(), "v8::String::NewExternal()"));
i::Handle<i::String> result = NewExternalStringHandle(isolate, resource);
isolate->heap()->external_string_table()->AddString(*result);
return Utils::ToLocal(result);
@@ -5959,6 +5963,10 @@ bool
v8::String::MakeExternal(v8::String::ExternalStringResource* resource) {
return false;
}
CHECK(resource && resource->data());
+ // Resource pointers need to look like Smis since ExternalString objects
+ // are sometimes put into old pointer space (see
i::String::MakeExternal).
+ CHECK(EncodeAlignedAsSmi(resource, "v8::String::MakeExternal()"));
+
CHECK(EncodeAlignedAsSmi(resource->data(), "v8::String::MakeExternal()"));
bool result = obj->MakeExternal(resource);
if (result && !obj->IsInternalizedString()) {
isolate->heap()->external_string_table()->AddString(*obj);
--
--
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.