JSValue JSNPObject::propertyGetter(ExecState* exec, JSValue slotBase, PropertyName propertyName) { JSNPObject* thisObj = static_cast<JSNPObject*>(asObject(slotBase)); ASSERT_GC_OBJECT_INHERITS(thisObj, &s_info); if (!thisObj->m_npObject) return throwInvalidAccessError(exec); if (!thisObj->m_npObject->_class->getProperty) return jsUndefined(); NPVariant result; VOID_TO_NPVARIANT(result); // Calling NPClass::getProperty will call into plug-in code, and there's no telling what the plug-in can do. // (including destroying the plug-in). Because of this, we make sure to keep the plug-in alive until // the call has finished. NPRuntimeObjectMap::PluginProtector protector(thisObj->m_objectMap); bool returnValue; { JSLock::DropAllLocks dropAllLocks(SilenceAssertionsOnly); NPIdentifier npIdentifier = npIdentifierFromIdentifier(propertyName); returnValue = thisObj->m_npObject->_class->getProperty(thisObj->m_npObject, npIdentifier, &result); NPRuntimeObjectMap::moveGlobalExceptionToExecState(exec); } if (!returnValue) return jsUndefined(); JSValue propertyValue = thisObj->m_objectMap->convertNPVariantToJSValue(exec, thisObj->globalObject(), result); releaseNPVariantValue(&result); return propertyValue; }
bool JSNPObject::getOwnPropertySlot(JSCell* cell, ExecState* exec, PropertyName propertyName, PropertySlot& slot) { JSNPObject* thisObject = JSC::jsCast<JSNPObject*>(cell); ASSERT_GC_OBJECT_INHERITS(thisObject, &s_info); if (!thisObject->m_npObject) { throwInvalidAccessError(exec); return false; } NPIdentifier npIdentifier = npIdentifierFromIdentifier(propertyName); // First, check if the NPObject has a property with this name. if (thisObject->m_npObject->_class->hasProperty && thisObject->m_npObject->_class->hasProperty(thisObject->m_npObject, npIdentifier)) { slot.setCustom(thisObject, thisObject->propertyGetter); return true; } // Second, check if the NPObject has a method with this name. if (thisObject->m_npObject->_class->hasMethod && thisObject->m_npObject->_class->hasMethod(thisObject->m_npObject, npIdentifier)) { slot.setCustom(thisObject, thisObject->methodGetter); return true; } return false; }
bool JSNPObject::getOwnPropertyDescriptor(JSObject* object, ExecState* exec, PropertyName propertyName, PropertyDescriptor& descriptor) { JSNPObject* thisObject = jsCast<JSNPObject*>(object); ASSERT_GC_OBJECT_INHERITS(thisObject, &s_info); if (!thisObject->m_npObject) { throwInvalidAccessError(exec); return false; } NPIdentifier npIdentifier = npIdentifierFromIdentifier(propertyName); // First, check if the NPObject has a property with this name. if (thisObject->m_npObject->_class->hasProperty && thisObject->m_npObject->_class->hasProperty(thisObject->m_npObject, npIdentifier)) { PropertySlot slot; slot.setCustom(thisObject, propertyGetter); descriptor.setDescriptor(slot.getValue(exec, propertyName), DontDelete); return true; } // Second, check if the NPObject has a method with this name. if (thisObject->m_npObject->_class->hasMethod && thisObject->m_npObject->_class->hasMethod(thisObject->m_npObject, npIdentifier)) { PropertySlot slot; slot.setCustom(thisObject, methodGetter); descriptor.setDescriptor(slot.getValue(exec, propertyName), DontDelete | ReadOnly); return true; } return false; }
bool JSNPObject::getOwnPropertySlot(JSObject* object, ExecState* exec, PropertyName propertyName, PropertySlot& slot) { JSNPObject* thisObject = JSC::jsCast<JSNPObject*>(object); ASSERT_GC_OBJECT_INHERITS(thisObject, info()); if (!thisObject->m_npObject) { throwInvalidAccessError(exec); return false; } NPIdentifier npIdentifier = npIdentifierFromIdentifier(propertyName); // Calling NPClass::invoke will call into plug-in code, and there's no telling what the plug-in can do. // (including destroying the plug-in). Because of this, we make sure to keep the plug-in alive until // the call has finished. NPRuntimeObjectMap::PluginProtector protector(thisObject->m_objectMap); // First, check if the NPObject has a property with this name. if (thisObject->m_npObject->_class->hasProperty && thisObject->m_npObject->_class->hasProperty(thisObject->m_npObject, npIdentifier)) { slot.setCustom(thisObject, DontDelete, thisObject->propertyGetter); return true; } // Second, check if the NPObject has a method with this name. if (thisObject->m_npObject->_class->hasMethod && thisObject->m_npObject->_class->hasMethod(thisObject->m_npObject, npIdentifier)) { slot.setCustom(thisObject, DontDelete | ReadOnly, thisObject->methodGetter); return true; } return false; }
bool JSNPObject::getOwnPropertyDescriptor(ExecState* exec, const Identifier& propertyName, PropertyDescriptor& descriptor) { if (!m_npObject) { throwInvalidAccessError(exec); return false; } NPIdentifier npIdentifier = npIdentifierFromIdentifier(propertyName); // First, check if the NPObject has a property with this name. if (m_npObject->_class->hasProperty && m_npObject->_class->hasProperty(m_npObject, npIdentifier)) { PropertySlot slot; slot.setCustom(this, propertyGetter); descriptor.setDescriptor(slot.getValue(exec, propertyName), DontDelete); return true; } // Second, check if the NPObject has a method with this name. if (m_npObject->_class->hasMethod && m_npObject->_class->hasMethod(m_npObject, npIdentifier)) { PropertySlot slot; slot.setCustom(this, methodGetter); descriptor.setDescriptor(slot.getValue(exec, propertyName), DontDelete | ReadOnly); return true; } return false; }
JSValue JSNPObject::methodGetter(ExecState* exec, JSValue slotBase, const Identifier& methodName) { JSNPObject* thisObj = static_cast<JSNPObject*>(asObject(slotBase)); if (!thisObj->m_npObject) return throwInvalidAccessError(exec); NPIdentifier npIdentifier = npIdentifierFromIdentifier(methodName); return new (exec) JSNPMethod(exec, thisObj->globalObject(), methodName, npIdentifier); }
JSValue JSNPObject::methodGetter(ExecState* exec, JSValue slotBase, PropertyName methodName) { JSNPObject* thisObj = static_cast<JSNPObject*>(asObject(slotBase)); ASSERT_GC_OBJECT_INHERITS(thisObj, &s_info); if (!thisObj->m_npObject) return throwInvalidAccessError(exec); NPIdentifier npIdentifier = npIdentifierFromIdentifier(methodName); return JSNPMethod::create(exec, thisObj->globalObject(), methodName.ustring(), npIdentifier); }
EncodedJSValue JSNPObject::methodGetter(ExecState* exec, EncodedJSValue slotBase, EncodedJSValue, PropertyName propertyName) { JSNPObject* thisObj = jsCast<JSNPObject*>(JSValue::decode(slotBase)); ASSERT_GC_OBJECT_INHERITS(thisObj, info()); if (!thisObj->m_npObject) return JSValue::encode(throwInvalidAccessError(exec)); NPIdentifier npIdentifier = npIdentifierFromIdentifier(propertyName); return JSValue::encode(JSNPMethod::create(exec, thisObj->globalObject(), propertyName.publicName(), npIdentifier)); }
void JSNPObject::put(JSCell* cell, ExecState* exec, PropertyName propertyName, JSValue value, PutPropertySlot&) { JSNPObject* thisObject = JSC::jsCast<JSNPObject*>(cell); ASSERT_GC_OBJECT_INHERITS(thisObject, &s_info); if (!thisObject->m_npObject) { throwInvalidAccessError(exec); return; } NPIdentifier npIdentifier = npIdentifierFromIdentifier(propertyName); if (!thisObject->m_npObject->_class->hasProperty || !thisObject->m_npObject->_class->hasProperty(thisObject->m_npObject, npIdentifier)) { // FIXME: Should we throw an exception here? return; } if (!thisObject->m_npObject->_class->setProperty) return; NPVariant variant; thisObject->m_objectMap->convertJSValueToNPVariant(exec, value, variant); // Calling NPClass::setProperty will call into plug-in code, and there's no telling what the plug-in can do. // (including destroying the plug-in). Because of this, we make sure to keep the plug-in alive until // the call has finished. NPRuntimeObjectMap::PluginProtector protector(thisObject->m_objectMap); { JSLock::DropAllLocks dropAllLocks(SilenceAssertionsOnly); thisObject->m_npObject->_class->setProperty(thisObject->m_npObject, npIdentifier, &variant); NPRuntimeObjectMap::moveGlobalExceptionToExecState(exec); // FIXME: Should we throw an exception if setProperty returns false? } releaseNPVariantValue(&variant); }
bool JSNPObject::getOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot) { if (!m_npObject) { throwInvalidAccessError(exec); return false; } NPIdentifier npIdentifier = npIdentifierFromIdentifier(propertyName); // First, check if the NPObject has a property with this name. if (m_npObject->_class->hasProperty && m_npObject->_class->hasProperty(m_npObject, npIdentifier)) { slot.setCustom(this, propertyGetter); return true; } // Second, check if the NPObject has a method with this name. if (m_npObject->_class->hasMethod && m_npObject->_class->hasMethod(m_npObject, npIdentifier)) { slot.setCustom(this, methodGetter); return true; } return false; }
bool JSNPObject::deleteProperty(JSCell* cell, ExecState* exec, PropertyName propertyName) { return jsCast<JSNPObject*>(cell)->deleteProperty(exec, npIdentifierFromIdentifier(propertyName)); }