Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5)

Unified Diff: src/api.cc

Issue 155635: Introduce faster utilty methods for storing and retrieving native pointers (Closed)
Patch Set: last pass Created 11 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « include/v8.h ('k') | test/cctest/test-api.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/api.cc
diff --git a/src/api.cc b/src/api.cc
index 145fa9d9b82760a62072278e3cd643344f37021c..c23efeb72a2966b2c662f49dad5e199a56e12fd7 100644
--- a/src/api.cc
+++ b/src/api.cc
@@ -2465,6 +2465,43 @@ void v8::Object::SetInternalField(int index, v8::Handle<Value> value) {
}
+void* v8::Object::GetPointerFromInternalField(int index) {
+ i::Handle<i::JSObject> obj = Utils::OpenHandle(this);
+ i::Object* pointer = obj->GetInternalField(index);
+ if (pointer->IsSmi()) {
+ // Fast case, aligned native pointer.
+ return pointer;
+ }
+
+ // Read from uninitialized field.
+ if (!pointer->IsProxy()) {
+ // Play safe even if it's something unexpected.
+ ASSERT(pointer->IsUndefined());
+ return NULL;
+ }
+
+ // Unaligned native pointer
+ return reinterpret_cast<void*>(i::Proxy::cast(pointer)->proxy());
+}
+
+
+void v8::Object::SetPointerInInternalField(int index, void* value) {
+ i::Handle<i::JSObject> obj = Utils::OpenHandle(this);
+ i::Object* as_object = reinterpret_cast<i::Object*>(value);
+ if (as_object->IsSmi()) {
+ // Aligned pointer, store as is.
+ obj->SetInternalField(index, as_object);
+ } else {
+ // Currently internal fields are used by DOM wrappers which
+ // only get GCed by the mark-sweep collector,
+ // so let's put proxy into old space.
+ i::Proxy* proxy = *i::Factory::NewProxy(reinterpret_cast<i::Address>(value),
+ i::TENURED);
+ obj->SetInternalField(index, proxy);
+ }
+}
+
+
// --- E n v i r o n m e n t ---
bool v8::V8::Initialize() {
« no previous file with comments | « include/v8.h ('k') | test/cctest/test-api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698