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

Side by Side Diff: Source/bindings/core/v8/NPV8Object.cpp

Issue 456683002: bindings: Introduces type-check for the internal pointers. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 4 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2004, 2006 Apple Computer, Inc. All rights reserved. 2 * Copyright (C) 2004, 2006 Apple Computer, Inc. All rights reserved.
3 * Copyright (C) 2007, 2008, 2009 Google, Inc. All rights reserved. 3 * Copyright (C) 2007, 2008, 2009 Google, Inc. All rights reserved.
4 * Copyright (C) 2014 Opera Software ASA. All rights reserved. 4 * Copyright (C) 2014 Opera Software ASA. All rights reserved.
5 * 5 *
6 * Redistribution and use in source and binary forms, with or without 6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions 7 * modification, are permitted provided that the following conditions
8 * are met: 8 * are met:
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 if (identifier->isString) 105 if (identifier->isString)
106 return v8AtomicString(isolate, static_cast<const char*>(identifier->valu e.string)); 106 return v8AtomicString(isolate, static_cast<const char*>(identifier->valu e.string));
107 107
108 char buffer[32]; 108 char buffer[32];
109 snprintf(buffer, sizeof(buffer), "%d", identifier->value.number); 109 snprintf(buffer, sizeof(buffer), "%d", identifier->value.number);
110 return v8AtomicString(isolate, buffer); 110 return v8AtomicString(isolate, buffer);
111 } 111 }
112 112
113 NPObject* v8ObjectToNPObject(v8::Handle<v8::Object> object) 113 NPObject* v8ObjectToNPObject(v8::Handle<v8::Object> object)
114 { 114 {
115 return reinterpret_cast<NPObject*>(object->GetAlignedPointerFromInternalFiel d(v8DOMWrapperObjectIndex)); 115 return reinterpret_cast<NPObject*>(toInternalPointer(object));
116 } 116 }
117 117
118 bool isWrappedNPObject(v8::Handle<v8::Object> object) 118 bool isWrappedNPObject(v8::Handle<v8::Object> object)
119 { 119 {
120 if (object->InternalFieldCount() == npObjectInternalFieldCount) { 120 if (object->InternalFieldCount() == npObjectInternalFieldCount) {
121 const WrapperTypeInfo* typeInfo = static_cast<const WrapperTypeInfo*>(ob ject->GetAlignedPointerFromInternalField(v8DOMWrapperTypeIndex)); 121 const WrapperTypeInfo* typeInfo = static_cast<const WrapperTypeInfo*>(ob ject->GetAlignedPointerFromInternalField(v8DOMWrapperTypeIndex));
122 return typeInfo == npObjectTypeInfo(); 122 return typeInfo == npObjectTypeInfo();
123 } 123 }
124 return false; 124 return false;
125 } 125 }
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 V8NPObject* npObjectToV8NPObject(NPObject* npObject) 170 V8NPObject* npObjectToV8NPObject(NPObject* npObject)
171 { 171 {
172 if (npObject->_class != &V8NPObjectClass) 172 if (npObject->_class != &V8NPObjectClass)
173 return 0; 173 return 0;
174 V8NPObject* v8NpObject = reinterpret_cast<V8NPObject*>(npObject); 174 V8NPObject* v8NpObject = reinterpret_cast<V8NPObject*>(npObject);
175 if (v8NpObject->v8Object.IsEmpty()) 175 if (v8NpObject->v8Object.IsEmpty())
176 return 0; 176 return 0;
177 return v8NpObject; 177 return v8NpObject;
178 } 178 }
179 179
180 ScriptWrappableBase* npObjectToInternalPointer(NPObject* npObject)
181 {
182 return reinterpret_cast<ScriptWrappableBase*>(npObject);
183 }
184
180 void disposeUnderlyingV8Object(NPObject* npObject, v8::Isolate* isolate) 185 void disposeUnderlyingV8Object(NPObject* npObject, v8::Isolate* isolate)
181 { 186 {
182 ASSERT(npObject); 187 ASSERT(npObject);
183 V8NPObject* v8NpObject = npObjectToV8NPObject(npObject); 188 V8NPObject* v8NpObject = npObjectToV8NPObject(npObject);
184 if (!v8NpObject) 189 if (!v8NpObject)
185 return; 190 return;
186 v8::HandleScope scope(isolate); 191 v8::HandleScope scope(isolate);
187 v8::Handle<v8::Object> v8Object = v8::Local<v8::Object>::New(isolate, v8NpOb ject->v8Object); 192 v8::Handle<v8::Object> v8Object = v8::Local<v8::Object>::New(isolate, v8NpOb ject->v8Object);
188 ASSERT(!v8Object->CreationContext().IsEmpty()); 193 ASSERT(!v8Object->CreationContext().IsEmpty());
189 if (V8PerContextData* perContextData = V8PerContextData::from(v8Object->Crea tionContext())) { 194 if (V8PerContextData* perContextData = V8PerContextData::from(v8Object->Crea tionContext())) {
(...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after
607 612
608 convertV8ObjectToNPVariant(resultObject, npObject, result, isolate); 613 convertV8ObjectToNPVariant(resultObject, npObject, result, isolate);
609 return true; 614 return true;
610 } 615 }
611 616
612 if (NP_CLASS_STRUCT_VERSION_HAS_CTOR(npObject->_class) && npObject->_class-> construct) 617 if (NP_CLASS_STRUCT_VERSION_HAS_CTOR(npObject->_class) && npObject->_class-> construct)
613 return npObject->_class->construct(npObject, arguments, argumentCount, r esult); 618 return npObject->_class->construct(npObject, arguments, argumentCount, r esult);
614 619
615 return false; 620 return false;
616 } 621 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698