| OLD | NEW |
| 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 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
| 7 * are met: | 7 * are met: |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 using namespace WebCore; | 50 using namespace WebCore; |
| 51 | 51 |
| 52 namespace WebCore { | 52 namespace WebCore { |
| 53 | 53 |
| 54 WrapperTypeInfo* npObjectTypeInfo() | 54 WrapperTypeInfo* npObjectTypeInfo() |
| 55 { | 55 { |
| 56 static WrapperTypeInfo typeInfo = { 0, 0, 0, 0 }; | 56 static WrapperTypeInfo typeInfo = { 0, 0, 0, 0 }; |
| 57 return &typeInfo; | 57 return &typeInfo; |
| 58 } | 58 } |
| 59 | 59 |
| 60 typedef HashMap<int, V8NPObject*> V8NPObjectMap; | 60 typedef Vector<V8NPObject*> V8NPObjectVector; |
| 61 typedef HashMap<int, V8NPObjectVector> V8NPObjectMap; |
| 61 | 62 |
| 62 static V8NPObjectMap* staticV8NPObjectMap() | 63 static V8NPObjectMap* staticV8NPObjectMap() |
| 63 { | 64 { |
| 64 DEFINE_STATIC_LOCAL(V8NPObjectMap, v8npObjectMap, ()); | 65 DEFINE_STATIC_LOCAL(V8NPObjectMap, v8npObjectMap, ()); |
| 65 return &v8npObjectMap; | 66 return &v8npObjectMap; |
| 66 } | 67 } |
| 67 | 68 |
| 68 // FIXME: Comments on why use malloc and free. | 69 // FIXME: Comments on why use malloc and free. |
| 69 static NPObject* allocV8NPObject(NPP, NPClass*) | 70 static NPObject* allocV8NPObject(NPP, NPClass*) |
| 70 { | 71 { |
| 71 return static_cast<NPObject*>(malloc(sizeof(V8NPObject))); | 72 return static_cast<NPObject*>(malloc(sizeof(V8NPObject))); |
| 72 } | 73 } |
| 73 | 74 |
| 74 static void freeV8NPObject(NPObject* npObject) | 75 static void freeV8NPObject(NPObject* npObject) |
| 75 { | 76 { |
| 76 V8NPObject* v8NpObject = reinterpret_cast<V8NPObject*>(npObject); | 77 V8NPObject* v8NpObject = reinterpret_cast<V8NPObject*>(npObject); |
| 77 if (int v8ObjectHash = v8NpObject->v8Object->GetIdentityHash()) { | 78 if (int v8ObjectHash = v8NpObject->v8Object->GetIdentityHash()) { |
| 78 ASSERT(staticV8NPObjectMap()->contains(v8ObjectHash)); | 79 V8NPObjectMap::iterator iter = staticV8NPObjectMap()->find(v8ObjectHash)
; |
| 79 staticV8NPObjectMap()->remove(v8ObjectHash); | 80 if (iter != staticV8NPObjectMap()->end()) { |
| 81 V8NPObjectVector& objects = iter->second; |
| 82 for (size_t index = 0; index < objects.size(); ++index) { |
| 83 if (objects.at(index) == v8NpObject) { |
| 84 objects.remove(index); |
| 85 break; |
| 86 } |
| 87 } |
| 88 if (objects.isEmpty()) |
| 89 staticV8NPObjectMap()->remove(v8ObjectHash); |
| 90 } else |
| 91 ASSERT_NOT_REACHED(); |
| 80 } else { | 92 } else { |
| 81 ASSERT(!v8::Context::InContext()); | 93 ASSERT(!v8::Context::InContext()); |
| 82 staticV8NPObjectMap()->clear(); | 94 staticV8NPObjectMap()->clear(); |
| 83 } | 95 } |
| 84 | 96 |
| 85 #ifndef NDEBUG | 97 #ifndef NDEBUG |
| 86 V8GCController::unregisterGlobalHandle(v8NpObject, v8NpObject->v8Object); | 98 V8GCController::unregisterGlobalHandle(v8NpObject, v8NpObject->v8Object); |
| 87 #endif | 99 #endif |
| 88 v8NpObject->v8Object.Dispose(); | 100 v8NpObject->v8Object.Dispose(); |
| 89 free(v8NpObject); | 101 free(v8NpObject); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 if (typeInfo == npObjectTypeInfo()) { | 144 if (typeInfo == npObjectTypeInfo()) { |
| 133 | 145 |
| 134 NPObject* returnValue = v8ObjectToNPObject(object); | 146 NPObject* returnValue = v8ObjectToNPObject(object); |
| 135 _NPN_RetainObject(returnValue); | 147 _NPN_RetainObject(returnValue); |
| 136 return returnValue; | 148 return returnValue; |
| 137 } | 149 } |
| 138 } | 150 } |
| 139 | 151 |
| 140 int v8ObjectHash = object->GetIdentityHash(); | 152 int v8ObjectHash = object->GetIdentityHash(); |
| 141 ASSERT(v8ObjectHash); | 153 ASSERT(v8ObjectHash); |
| 142 if (staticV8NPObjectMap()->contains(v8ObjectHash)) { | 154 V8NPObjectMap::iterator iter = staticV8NPObjectMap()->find(v8ObjectHash); |
| 143 V8NPObject* v8npObject = staticV8NPObjectMap()->get(v8ObjectHash); | 155 if (iter != staticV8NPObjectMap()->end()) { |
| 144 ASSERT(v8npObject->v8Object == object); | 156 V8NPObjectVector& objects = iter->second; |
| 145 _NPN_RetainObject(&v8npObject->object); | 157 for (size_t index = 0; index < objects.size(); ++index) { |
| 146 return reinterpret_cast<NPObject*>(v8npObject); | 158 V8NPObject* v8npObject = objects.at(index); |
| 159 if (v8npObject->rootObject == root) { |
| 160 ASSERT(v8npObject->v8Object == object); |
| 161 _NPN_RetainObject(&v8npObject->object); |
| 162 return reinterpret_cast<NPObject*>(v8npObject); |
| 163 } |
| 164 } |
| 165 } else { |
| 166 iter = staticV8NPObjectMap()->set(v8ObjectHash, V8NPObjectVector()).firs
t; |
| 147 } | 167 } |
| 148 | 168 |
| 149 V8NPObject* v8npObject = reinterpret_cast<V8NPObject*>(_NPN_CreateObject(npp
, &V8NPObjectClass)); | 169 V8NPObject* v8npObject = reinterpret_cast<V8NPObject*>(_NPN_CreateObject(npp
, &V8NPObjectClass)); |
| 150 v8npObject->v8Object = v8::Persistent<v8::Object>::New(object); | 170 v8npObject->v8Object = v8::Persistent<v8::Object>::New(object); |
| 151 #ifndef NDEBUG | 171 #ifndef NDEBUG |
| 152 V8GCController::registerGlobalHandle(NPOBJECT, v8npObject, v8npObject->v8Obj
ect); | 172 V8GCController::registerGlobalHandle(NPOBJECT, v8npObject, v8npObject->v8Obj
ect); |
| 153 #endif | 173 #endif |
| 154 v8npObject->rootObject = root; | 174 v8npObject->rootObject = root; |
| 155 | 175 |
| 156 staticV8NPObjectMap()->set(v8ObjectHash, v8npObject); | 176 iter->second.append(v8npObject); |
| 157 | 177 |
| 158 return reinterpret_cast<NPObject*>(v8npObject); | 178 return reinterpret_cast<NPObject*>(v8npObject); |
| 159 } | 179 } |
| 160 | 180 |
| 161 } // namespace WebCore | 181 } // namespace WebCore |
| 162 | 182 |
| 163 bool _NPN_Invoke(NPP npp, NPObject* npObject, NPIdentifier methodName, const NPV
ariant* arguments, uint32_t argumentCount, NPVariant* result) | 183 bool _NPN_Invoke(NPP npp, NPObject* npObject, NPIdentifier methodName, const NPV
ariant* arguments, uint32_t argumentCount, NPVariant* result) |
| 164 { | 184 { |
| 165 if (!npObject) | 185 if (!npObject) |
| 166 return false; | 186 return false; |
| (...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 564 | 584 |
| 565 convertV8ObjectToNPVariant(resultObject, npObject, result); | 585 convertV8ObjectToNPVariant(resultObject, npObject, result); |
| 566 return true; | 586 return true; |
| 567 } | 587 } |
| 568 | 588 |
| 569 if (NP_CLASS_STRUCT_VERSION_HAS_CTOR(npObject->_class) && npObject->_class->
construct) | 589 if (NP_CLASS_STRUCT_VERSION_HAS_CTOR(npObject->_class) && npObject->_class->
construct) |
| 570 return npObject->_class->construct(npObject, arguments, argumentCount, r
esult); | 590 return npObject->_class->construct(npObject, arguments, argumentCount, r
esult); |
| 571 | 591 |
| 572 return false; | 592 return false; |
| 573 } | 593 } |
| OLD | NEW |