OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2006, 2007, 2008, 2009 Google Inc. All rights reserved. | 2 * Copyright (C) 2006, 2007, 2008, 2009 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * 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 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
410 // Must remove from our map before calling _NPN_ReleaseObject(). _NPN_Releas
eObject can | 410 // Must remove from our map before calling _NPN_ReleaseObject(). _NPN_Releas
eObject can |
411 // call forgetV8ObjectForNPObject, which uses the table as well. | 411 // call forgetV8ObjectForNPObject, which uses the table as well. |
412 staticNPObjectMap().removeAndDispose(npObject); | 412 staticNPObjectMap().removeAndDispose(npObject); |
413 | 413 |
414 if (_NPN_IsAlive(npObject)) | 414 if (_NPN_IsAlive(npObject)) |
415 _NPN_ReleaseObject(npObject); | 415 _NPN_ReleaseObject(npObject); |
416 } | 416 } |
417 | 417 |
418 v8::Local<v8::Object> createV8ObjectForNPObject(NPObject* object, NPObject* root
) | 418 v8::Local<v8::Object> createV8ObjectForNPObject(NPObject* object, NPObject* root
) |
419 { | 419 { |
420 static v8::Persistent<v8::FunctionTemplate> npObjectDesc; | 420 static v8::Eternal<v8::FunctionTemplate> npObjectDesc; |
421 | 421 |
422 ASSERT(v8::Context::InContext()); | 422 ASSERT(v8::Context::InContext()); |
423 | 423 |
424 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | 424 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
425 | 425 |
426 // If this is a v8 object, just return it. | 426 // If this is a v8 object, just return it. |
427 V8NPObject* v8NPObject = npObjectToV8NPObject(object); | 427 V8NPObject* v8NPObject = npObjectToV8NPObject(object); |
428 if (v8NPObject) | 428 if (v8NPObject) |
429 return v8::Local<v8::Object>::New(isolate, v8NPObject->v8Object); | 429 return v8::Local<v8::Object>::New(isolate, v8NPObject->v8Object); |
430 | 430 |
431 // If we've already wrapped this object, just return it. | 431 // If we've already wrapped this object, just return it. |
432 v8::Handle<v8::Object> wrapper = staticNPObjectMap().newLocal(object, isolat
e); | 432 v8::Handle<v8::Object> wrapper = staticNPObjectMap().newLocal(object, isolat
e); |
433 if (!wrapper.IsEmpty()) | 433 if (!wrapper.IsEmpty()) |
434 return wrapper; | 434 return wrapper; |
435 | 435 |
436 // FIXME: we should create a Wrapper type as a subclass of JSObject. It has
two internal fields, field 0 is the wrapped | 436 // FIXME: we should create a Wrapper type as a subclass of JSObject. It has
two internal fields, field 0 is the wrapped |
437 // pointer, and field 1 is the type. There should be an api function that re
turns unused type id. The same Wrapper type | 437 // pointer, and field 1 is the type. There should be an api function that re
turns unused type id. The same Wrapper type |
438 // can be used by DOM bindings. | 438 // can be used by DOM bindings. |
439 if (npObjectDesc.IsEmpty()) { | 439 if (npObjectDesc.IsEmpty()) { |
440 v8::Handle<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(); | 440 v8::Local<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(); |
441 templ->InstanceTemplate()->SetInternalFieldCount(npObjectInternalFieldCo
unt); | 441 templ->InstanceTemplate()->SetInternalFieldCount(npObjectInternalFieldCo
unt); |
442 templ->InstanceTemplate()->SetNamedPropertyHandler(npObjectNamedProperty
Getter, npObjectNamedPropertySetter, npObjectQueryProperty, 0, npObjectNamedProp
ertyEnumerator); | 442 templ->InstanceTemplate()->SetNamedPropertyHandler(npObjectNamedProperty
Getter, npObjectNamedPropertySetter, npObjectQueryProperty, 0, npObjectNamedProp
ertyEnumerator); |
443 templ->InstanceTemplate()->SetIndexedPropertyHandler(npObjectIndexedProp
ertyGetter, npObjectIndexedPropertySetter, 0, 0, npObjectIndexedPropertyEnumerat
or); | 443 templ->InstanceTemplate()->SetIndexedPropertyHandler(npObjectIndexedProp
ertyGetter, npObjectIndexedPropertySetter, 0, 0, npObjectIndexedPropertyEnumerat
or); |
444 templ->InstanceTemplate()->SetCallAsFunctionHandler(npObjectInvokeDefaul
tHandler); | 444 templ->InstanceTemplate()->SetCallAsFunctionHandler(npObjectInvokeDefaul
tHandler); |
445 npObjectDesc.Reset(isolate, templ); | 445 npObjectDesc.Set(isolate, templ); |
446 } | 446 } |
447 | 447 |
448 // FIXME: Move staticNPObjectMap() to DOMDataStore. | 448 // FIXME: Move staticNPObjectMap() to DOMDataStore. |
449 // Use V8DOMWrapper::createWrapper() and | 449 // Use V8DOMWrapper::createWrapper() and |
450 // V8DOMWrapper::associateObjectWithWrapper() | 450 // V8DOMWrapper::associateObjectWithWrapper() |
451 // to create a wrapper object. | 451 // to create a wrapper object. |
452 v8::Handle<v8::Function> v8Function = v8::Local<v8::FunctionTemplate>::New(i
solate, npObjectDesc)->GetFunction(); | 452 v8::Handle<v8::Function> v8Function = npObjectDesc.Get(isolate)->GetFunction
(); |
453 v8::Local<v8::Object> value = V8ObjectConstructor::newInstance(v8Function); | 453 v8::Local<v8::Object> value = V8ObjectConstructor::newInstance(v8Function); |
454 if (value.IsEmpty()) | 454 if (value.IsEmpty()) |
455 return value; | 455 return value; |
456 | 456 |
457 V8DOMWrapper::setNativeInfo(value, npObjectTypeInfo(), object); | 457 V8DOMWrapper::setNativeInfo(value, npObjectTypeInfo(), object); |
458 | 458 |
459 // KJS retains the object as part of its wrapper (see Bindings::CInstance). | 459 // KJS retains the object as part of its wrapper (see Bindings::CInstance). |
460 _NPN_RetainObject(object); | 460 _NPN_RetainObject(object); |
461 _NPN_RegisterObject(object, root); | 461 _NPN_RegisterObject(object, root); |
462 | 462 |
463 WrapperConfiguration configuration = buildWrapperConfiguration(object, Wrapp
erConfiguration::Dependent); | 463 WrapperConfiguration configuration = buildWrapperConfiguration(object, Wrapp
erConfiguration::Dependent); |
464 staticNPObjectMap().set(object, value, configuration); | 464 staticNPObjectMap().set(object, value, configuration); |
465 ASSERT(V8DOMWrapper::maybeDOMWrapper(value)); | 465 ASSERT(V8DOMWrapper::maybeDOMWrapper(value)); |
466 return value; | 466 return value; |
467 } | 467 } |
468 | 468 |
469 void forgetV8ObjectForNPObject(NPObject* object) | 469 void forgetV8ObjectForNPObject(NPObject* object) |
470 { | 470 { |
471 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | 471 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
472 v8::HandleScope scope(isolate); | 472 v8::HandleScope scope(isolate); |
473 v8::Handle<v8::Object> wrapper = staticNPObjectMap().newLocal(object, isolat
e); | 473 v8::Handle<v8::Object> wrapper = staticNPObjectMap().newLocal(object, isolat
e); |
474 if (!wrapper.IsEmpty()) { | 474 if (!wrapper.IsEmpty()) { |
475 V8DOMWrapper::clearNativeInfo(wrapper, npObjectTypeInfo()); | 475 V8DOMWrapper::clearNativeInfo(wrapper, npObjectTypeInfo()); |
476 staticNPObjectMap().removeAndDispose(object); | 476 staticNPObjectMap().removeAndDispose(object); |
477 _NPN_ReleaseObject(object); | 477 _NPN_ReleaseObject(object); |
478 } | 478 } |
479 } | 479 } |
480 | 480 |
481 } // namespace WebCore | 481 } // namespace WebCore |
OLD | NEW |