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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 | 59 |
60 // FIXME: Comments on why use malloc and free. | 60 // FIXME: Comments on why use malloc and free. |
61 static NPObject* allocV8NPObject(NPP, NPClass*) | 61 static NPObject* allocV8NPObject(NPP, NPClass*) |
62 { | 62 { |
63 return static_cast<NPObject*>(malloc(sizeof(V8NPObject))); | 63 return static_cast<NPObject*>(malloc(sizeof(V8NPObject))); |
64 } | 64 } |
65 | 65 |
66 static void freeV8NPObject(NPObject* npObject) | 66 static void freeV8NPObject(NPObject* npObject) |
67 { | 67 { |
68 V8NPObject* v8NpObject = reinterpret_cast<V8NPObject*>(npObject); | 68 V8NPObject* v8NpObject = reinterpret_cast<V8NPObject*>(npObject); |
69 disposeUnderlyingV8Object(npObject); | 69 disposeUnderlyingV8Object(npObject, v8::Isolate::GetCurrent()); |
70 free(v8NpObject); | 70 free(v8NpObject); |
71 } | 71 } |
72 | 72 |
73 static NPClass V8NPObjectClass = { | 73 static NPClass V8NPObjectClass = { |
74 NP_CLASS_STRUCT_VERSION, | 74 NP_CLASS_STRUCT_VERSION, |
75 allocV8NPObject, | 75 allocV8NPObject, |
76 freeV8NPObject, | 76 freeV8NPObject, |
77 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 | 77 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 |
78 }; | 78 }; |
79 | 79 |
(...skipping 27 matching lines...) Expand all Loading... |
107 char buffer[32]; | 107 char buffer[32]; |
108 snprintf(buffer, sizeof(buffer), "%d", identifier->value.number); | 108 snprintf(buffer, sizeof(buffer), "%d", identifier->value.number); |
109 return v8::String::NewSymbol(buffer); | 109 return v8::String::NewSymbol(buffer); |
110 } | 110 } |
111 | 111 |
112 NPObject* v8ObjectToNPObject(v8::Handle<v8::Object> object) | 112 NPObject* v8ObjectToNPObject(v8::Handle<v8::Object> object) |
113 { | 113 { |
114 return reinterpret_cast<NPObject*>(object->GetAlignedPointerFromInternalFiel
d(v8DOMWrapperObjectIndex)); | 114 return reinterpret_cast<NPObject*>(object->GetAlignedPointerFromInternalFiel
d(v8DOMWrapperObjectIndex)); |
115 } | 115 } |
116 | 116 |
117 NPObject* npCreateV8ScriptObject(NPP npp, v8::Handle<v8::Object> object, DOMWind
ow* root) | 117 NPObject* npCreateV8ScriptObject(NPP npp, v8::Handle<v8::Object> object, DOMWind
ow* root, v8::Isolate* isolate) |
118 { | 118 { |
119 // Check to see if this object is already wrapped. | 119 // Check to see if this object is already wrapped. |
120 if (object->InternalFieldCount() == npObjectInternalFieldCount) { | 120 if (object->InternalFieldCount() == npObjectInternalFieldCount) { |
121 WrapperTypeInfo* typeInfo = static_cast<WrapperTypeInfo*>(object->GetAli
gnedPointerFromInternalField(v8DOMWrapperTypeIndex)); | 121 WrapperTypeInfo* typeInfo = static_cast<WrapperTypeInfo*>(object->GetAli
gnedPointerFromInternalField(v8DOMWrapperTypeIndex)); |
122 if (typeInfo == npObjectTypeInfo()) { | 122 if (typeInfo == npObjectTypeInfo()) { |
123 NPObject* returnValue = v8ObjectToNPObject(object); | 123 NPObject* returnValue = v8ObjectToNPObject(object); |
124 _NPN_RetainObject(returnValue); | 124 _NPN_RetainObject(returnValue); |
125 return returnValue; | 125 return returnValue; |
126 } | 126 } |
127 } | 127 } |
(...skipping 16 matching lines...) Expand all Loading... |
144 } else { | 144 } else { |
145 iter = v8NPObjectMap->set(v8ObjectHash, V8NPObjectVector()).iterator
; | 145 iter = v8NPObjectMap->set(v8ObjectHash, V8NPObjectVector()).iterator
; |
146 } | 146 } |
147 objectVector = &iter->value; | 147 objectVector = &iter->value; |
148 } | 148 } |
149 | 149 |
150 V8NPObject* v8npObject = reinterpret_cast<V8NPObject*>(_NPN_CreateObject(npp
, &V8NPObjectClass)); | 150 V8NPObject* v8npObject = reinterpret_cast<V8NPObject*>(_NPN_CreateObject(npp
, &V8NPObjectClass)); |
151 // This is uninitialized memory, we need to clear it so that | 151 // This is uninitialized memory, we need to clear it so that |
152 // Persistent::Reset won't try to Dispose anything bogus. | 152 // Persistent::Reset won't try to Dispose anything bogus. |
153 v8npObject->v8Object.Clear(); | 153 v8npObject->v8Object.Clear(); |
154 v8npObject->v8Object.Reset(v8::Isolate::GetCurrent(), object); | 154 v8npObject->v8Object.Reset(isolate, object); |
155 v8npObject->rootObject = root; | 155 v8npObject->rootObject = root; |
156 | 156 |
157 if (objectVector) | 157 if (objectVector) |
158 objectVector->append(v8npObject); | 158 objectVector->append(v8npObject); |
159 | 159 |
160 return reinterpret_cast<NPObject*>(v8npObject); | 160 return reinterpret_cast<NPObject*>(v8npObject); |
161 } | 161 } |
162 | 162 |
163 V8NPObject* npObjectToV8NPObject(NPObject* npObject) | 163 V8NPObject* npObjectToV8NPObject(NPObject* npObject) |
164 { | 164 { |
165 if (npObject->_class != &V8NPObjectClass) | 165 if (npObject->_class != &V8NPObjectClass) |
166 return 0; | 166 return 0; |
167 V8NPObject* v8NpObject = reinterpret_cast<V8NPObject*>(npObject); | 167 V8NPObject* v8NpObject = reinterpret_cast<V8NPObject*>(npObject); |
168 if (v8NpObject->v8Object.IsEmpty()) | 168 if (v8NpObject->v8Object.IsEmpty()) |
169 return 0; | 169 return 0; |
170 return v8NpObject; | 170 return v8NpObject; |
171 } | 171 } |
172 | 172 |
173 void disposeUnderlyingV8Object(NPObject* npObject) | 173 void disposeUnderlyingV8Object(NPObject* npObject, v8::Isolate* isolate) |
174 { | 174 { |
175 ASSERT(npObject); | 175 ASSERT(npObject); |
176 V8NPObject* v8NpObject = npObjectToV8NPObject(npObject); | 176 V8NPObject* v8NpObject = npObjectToV8NPObject(npObject); |
177 if (!v8NpObject) | 177 if (!v8NpObject) |
178 return; | 178 return; |
179 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | |
180 v8::HandleScope scope(isolate); | 179 v8::HandleScope scope(isolate); |
181 v8::Handle<v8::Object> v8Object = v8::Local<v8::Object>::New(isolate, v8NpOb
ject->v8Object); | 180 v8::Handle<v8::Object> v8Object = v8::Local<v8::Object>::New(isolate, v8NpOb
ject->v8Object); |
182 ASSERT(!v8Object->CreationContext().IsEmpty()); | 181 ASSERT(!v8Object->CreationContext().IsEmpty()); |
183 if (V8PerContextData* perContextData = V8PerContextData::from(v8Object->Crea
tionContext())) { | 182 if (V8PerContextData* perContextData = V8PerContextData::from(v8Object->Crea
tionContext())) { |
184 V8NPObjectMap* v8NPObjectMap = perContextData->v8NPObjectMap(); | 183 V8NPObjectMap* v8NPObjectMap = perContextData->v8NPObjectMap(); |
185 int v8ObjectHash = v8Object->GetIdentityHash(); | 184 int v8ObjectHash = v8Object->GetIdentityHash(); |
186 ASSERT(v8ObjectHash); | 185 ASSERT(v8ObjectHash); |
187 V8NPObjectMap::iterator iter = v8NPObjectMap->find(v8ObjectHash); | 186 V8NPObjectMap::iterator iter = v8NPObjectMap->find(v8ObjectHash); |
188 if (iter != v8NPObjectMap->end()) { | 187 if (iter != v8NPObjectMap->end()) { |
189 V8NPObjectVector& objects = iter->value; | 188 V8NPObjectVector& objects = iter->value; |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
258 // Call the function object. | 257 // Call the function object. |
259 v8::Handle<v8::Function> function = v8::Handle<v8::Function>::Cast(functionO
bject); | 258 v8::Handle<v8::Function> function = v8::Handle<v8::Function>::Cast(functionO
bject); |
260 OwnArrayPtr<v8::Handle<v8::Value> > argv = createValueListFromVariantArgs(ar
guments, argumentCount, npObject, isolate); | 259 OwnArrayPtr<v8::Handle<v8::Value> > argv = createValueListFromVariantArgs(ar
guments, argumentCount, npObject, isolate); |
261 v8::Local<v8::Value> resultObject = frame->script()->callFunction(function,
v8Object, argumentCount, argv.get()); | 260 v8::Local<v8::Value> resultObject = frame->script()->callFunction(function,
v8Object, argumentCount, argv.get()); |
262 | 261 |
263 // If we had an error, return false. The spec is a little unclear here, but
says "Returns true if the method was | 262 // If we had an error, return false. The spec is a little unclear here, but
says "Returns true if the method was |
264 // successfully invoked". If we get an error return value, was that success
fully invoked? | 263 // successfully invoked". If we get an error return value, was that success
fully invoked? |
265 if (resultObject.IsEmpty()) | 264 if (resultObject.IsEmpty()) |
266 return false; | 265 return false; |
267 | 266 |
268 convertV8ObjectToNPVariant(resultObject, npObject, result); | 267 convertV8ObjectToNPVariant(resultObject, npObject, result, isolate); |
269 return true; | 268 return true; |
270 } | 269 } |
271 | 270 |
272 // FIXME: Fix it same as _NPN_Invoke (HandleScope and such). | 271 // FIXME: Fix it same as _NPN_Invoke (HandleScope and such). |
273 bool _NPN_InvokeDefault(NPP npp, NPObject* npObject, const NPVariant* arguments,
uint32_t argumentCount, NPVariant* result) | 272 bool _NPN_InvokeDefault(NPP npp, NPObject* npObject, const NPVariant* arguments,
uint32_t argumentCount, NPVariant* result) |
274 { | 273 { |
275 if (!npObject) | 274 if (!npObject) |
276 return false; | 275 return false; |
277 | 276 |
278 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | 277 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
(...skipping 29 matching lines...) Expand all Loading... |
308 ASSERT(frame); | 307 ASSERT(frame); |
309 | 308 |
310 OwnArrayPtr<v8::Handle<v8::Value> > argv = createValueListFromVariantArg
s(arguments, argumentCount, npObject, isolate); | 309 OwnArrayPtr<v8::Handle<v8::Value> > argv = createValueListFromVariantArg
s(arguments, argumentCount, npObject, isolate); |
311 resultObject = frame->script()->callFunction(function, functionObject, a
rgumentCount, argv.get()); | 310 resultObject = frame->script()->callFunction(function, functionObject, a
rgumentCount, argv.get()); |
312 } | 311 } |
313 // If we had an error, return false. The spec is a little unclear here, but
says "Returns true if the method was | 312 // If we had an error, return false. The spec is a little unclear here, but
says "Returns true if the method was |
314 // successfully invoked". If we get an error return value, was that success
fully invoked? | 313 // successfully invoked". If we get an error return value, was that success
fully invoked? |
315 if (resultObject.IsEmpty()) | 314 if (resultObject.IsEmpty()) |
316 return false; | 315 return false; |
317 | 316 |
318 convertV8ObjectToNPVariant(resultObject, npObject, result); | 317 convertV8ObjectToNPVariant(resultObject, npObject, result, isolate); |
319 return true; | 318 return true; |
320 } | 319 } |
321 | 320 |
322 bool _NPN_Evaluate(NPP npp, NPObject* npObject, NPString* npScript, NPVariant* r
esult) | 321 bool _NPN_Evaluate(NPP npp, NPObject* npObject, NPString* npScript, NPVariant* r
esult) |
323 { | 322 { |
324 // FIXME: Give the embedder a way to control this. | 323 // FIXME: Give the embedder a way to control this. |
325 bool popupsAllowed = false; | 324 bool popupsAllowed = false; |
326 return _NPN_EvaluateHelper(npp, popupsAllowed, npObject, npScript, result); | 325 return _NPN_EvaluateHelper(npp, popupsAllowed, npObject, npScript, result); |
327 } | 326 } |
328 | 327 |
329 bool _NPN_EvaluateHelper(NPP npp, bool popupsAllowed, NPObject* npObject, NPStri
ng* npScript, NPVariant* result) | 328 bool _NPN_EvaluateHelper(NPP npp, bool popupsAllowed, NPObject* npObject, NPStri
ng* npScript, NPVariant* result) |
330 { | 329 { |
331 VOID_TO_NPVARIANT(*result); | 330 VOID_TO_NPVARIANT(*result); |
332 if (!npObject) | 331 if (!npObject) |
333 return false; | 332 return false; |
334 | 333 |
335 V8NPObject* v8NpObject = npObjectToV8NPObject(npObject); | 334 V8NPObject* v8NpObject = npObjectToV8NPObject(npObject); |
336 if (!v8NpObject) | 335 if (!v8NpObject) |
337 return false; | 336 return false; |
338 | 337 |
339 v8::HandleScope handleScope(v8::Isolate::GetCurrent()); | 338 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
| 339 v8::HandleScope handleScope(isolate); |
340 v8::Handle<v8::Context> context = toV8Context(npp, npObject); | 340 v8::Handle<v8::Context> context = toV8Context(npp, npObject); |
341 if (context.IsEmpty()) | 341 if (context.IsEmpty()) |
342 return false; | 342 return false; |
343 | 343 |
344 v8::Context::Scope scope(context); | 344 v8::Context::Scope scope(context); |
345 ExceptionCatcher exceptionCatcher; | 345 ExceptionCatcher exceptionCatcher; |
346 | 346 |
347 // FIXME: Is this branch still needed after switching to using UserGestureIn
dicator? | 347 // FIXME: Is this branch still needed after switching to using UserGestureIn
dicator? |
348 String filename; | 348 String filename; |
349 if (!popupsAllowed) | 349 if (!popupsAllowed) |
350 filename = "npscript"; | 350 filename = "npscript"; |
351 | 351 |
352 Frame* frame = v8NpObject->rootObject->frame(); | 352 Frame* frame = v8NpObject->rootObject->frame(); |
353 ASSERT(frame); | 353 ASSERT(frame); |
354 | 354 |
355 String script = String::fromUTF8(npScript->UTF8Characters, npScript->UTF8Len
gth); | 355 String script = String::fromUTF8(npScript->UTF8Characters, npScript->UTF8Len
gth); |
356 | 356 |
357 UserGestureIndicator gestureIndicator(popupsAllowed ? DefinitelyProcessingNe
wUserGesture : PossiblyProcessingUserGesture); | 357 UserGestureIndicator gestureIndicator(popupsAllowed ? DefinitelyProcessingNe
wUserGesture : PossiblyProcessingUserGesture); |
358 v8::Local<v8::Value> v8result = frame->script()->compileAndRunScript(ScriptS
ourceCode(script, KURL(ParsedURLString, filename))); | 358 v8::Local<v8::Value> v8result = frame->script()->compileAndRunScript(ScriptS
ourceCode(script, KURL(ParsedURLString, filename))); |
359 | 359 |
360 if (v8result.IsEmpty()) | 360 if (v8result.IsEmpty()) |
361 return false; | 361 return false; |
362 | 362 |
363 if (_NPN_IsAlive(npObject)) | 363 if (_NPN_IsAlive(npObject)) |
364 convertV8ObjectToNPVariant(v8result, npObject, result); | 364 convertV8ObjectToNPVariant(v8result, npObject, result, isolate); |
365 return true; | 365 return true; |
366 } | 366 } |
367 | 367 |
368 bool _NPN_GetProperty(NPP npp, NPObject* npObject, NPIdentifier propertyName, NP
Variant* result) | 368 bool _NPN_GetProperty(NPP npp, NPObject* npObject, NPIdentifier propertyName, NP
Variant* result) |
369 { | 369 { |
370 if (!npObject) | 370 if (!npObject) |
371 return false; | 371 return false; |
372 | 372 |
373 if (V8NPObject* object = npObjectToV8NPObject(npObject)) { | 373 if (V8NPObject* object = npObjectToV8NPObject(npObject)) { |
374 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | 374 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
375 v8::HandleScope handleScope(isolate); | 375 v8::HandleScope handleScope(isolate); |
376 v8::Handle<v8::Context> context = toV8Context(npp, npObject); | 376 v8::Handle<v8::Context> context = toV8Context(npp, npObject); |
377 if (context.IsEmpty()) | 377 if (context.IsEmpty()) |
378 return false; | 378 return false; |
379 | 379 |
380 v8::Context::Scope scope(context); | 380 v8::Context::Scope scope(context); |
381 ExceptionCatcher exceptionCatcher; | 381 ExceptionCatcher exceptionCatcher; |
382 | 382 |
383 v8::Handle<v8::Object> obj = v8::Local<v8::Object>::New(isolate, object-
>v8Object); | 383 v8::Handle<v8::Object> obj = v8::Local<v8::Object>::New(isolate, object-
>v8Object); |
384 v8::Local<v8::Value> v8result = obj->Get(npIdentifierToV8Identifier(prop
ertyName)); | 384 v8::Local<v8::Value> v8result = obj->Get(npIdentifierToV8Identifier(prop
ertyName)); |
385 | 385 |
386 if (v8result.IsEmpty()) | 386 if (v8result.IsEmpty()) |
387 return false; | 387 return false; |
388 | 388 |
389 convertV8ObjectToNPVariant(v8result, npObject, result); | 389 convertV8ObjectToNPVariant(v8result, npObject, result, isolate); |
390 return true; | 390 return true; |
391 } | 391 } |
392 | 392 |
393 if (npObject->_class->hasProperty && npObject->_class->getProperty) { | 393 if (npObject->_class->hasProperty && npObject->_class->getProperty) { |
394 if (npObject->_class->hasProperty(npObject, propertyName)) | 394 if (npObject->_class->hasProperty(npObject, propertyName)) |
395 return npObject->_class->getProperty(npObject, propertyName, result)
; | 395 return npObject->_class->getProperty(npObject, propertyName, result)
; |
396 } | 396 } |
397 | 397 |
398 VOID_TO_NPVARIANT(*result); | 398 VOID_TO_NPVARIANT(*result); |
399 return false; | 399 return false; |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
596 if (!ctor->IsNull()) { | 596 if (!ctor->IsNull()) { |
597 Frame* frame = object->rootObject->frame(); | 597 Frame* frame = object->rootObject->frame(); |
598 ASSERT(frame); | 598 ASSERT(frame); |
599 OwnArrayPtr<v8::Handle<v8::Value> > argv = createValueListFromVarian
tArgs(arguments, argumentCount, npObject, isolate); | 599 OwnArrayPtr<v8::Handle<v8::Value> > argv = createValueListFromVarian
tArgs(arguments, argumentCount, npObject, isolate); |
600 resultObject = V8ObjectConstructor::newInstanceInDocument(ctor, argu
mentCount, argv.get(), frame ? frame->document() : 0); | 600 resultObject = V8ObjectConstructor::newInstanceInDocument(ctor, argu
mentCount, argv.get(), frame ? frame->document() : 0); |
601 } | 601 } |
602 | 602 |
603 if (resultObject.IsEmpty()) | 603 if (resultObject.IsEmpty()) |
604 return false; | 604 return false; |
605 | 605 |
606 convertV8ObjectToNPVariant(resultObject, npObject, result); | 606 convertV8ObjectToNPVariant(resultObject, npObject, result, isolate); |
607 return true; | 607 return true; |
608 } | 608 } |
609 | 609 |
610 if (NP_CLASS_STRUCT_VERSION_HAS_CTOR(npObject->_class) && npObject->_class->
construct) | 610 if (NP_CLASS_STRUCT_VERSION_HAS_CTOR(npObject->_class) && npObject->_class->
construct) |
611 return npObject->_class->construct(npObject, arguments, argumentCount, r
esult); | 611 return npObject->_class->construct(npObject, arguments, argumentCount, r
esult); |
612 | 612 |
613 return false; | 613 return false; |
614 } | 614 } |
OLD | NEW |