bool _NPN_HasProperty(NPP, NPObject* o, NPIdentifier propertyName) { if (o->_class == NPScriptObjectClass) { JavaScriptObject* obj = reinterpret_cast<JavaScriptObject*>(o); RootObject* rootObject = obj->rootObject; if (!rootObject || !rootObject->isValid()) return false; ExecState* exec = rootObject->globalObject()->globalExec(); PrivateIdentifier* i = static_cast<PrivateIdentifier*>(propertyName); JSLock lock(false); if (i->isString) { bool result = obj->imp->hasProperty(exec, identifierFromNPIdentifier(i->value.string)); exec->clearException(); return result; } bool result = obj->imp->hasProperty(exec, i->value.number); exec->clearException(); return result; } if (o->_class->hasProperty) return o->_class->hasProperty(o, propertyName); return false; }
bool _NPN_GetProperty(NPP, NPObject* o, NPIdentifier propertyName, NPVariant* variant) { if (o->_class == NPScriptObjectClass) { JavaScriptObject* obj = reinterpret_cast<JavaScriptObject*>(o); RootObject* rootObject = obj->rootObject; if (!rootObject || !rootObject->isValid()) return false; ExecState* exec = rootObject->globalObject()->globalExec(); PrivateIdentifier* i = static_cast<PrivateIdentifier*>(propertyName); JSLock lock(false); JSValue* result; if (i->isString) result = obj->imp->get(exec, identifierFromNPIdentifier(i->value.string)); else result = obj->imp->get(exec, i->value.number); convertValueToNPVariant(exec, result, variant); exec->clearException(); return true; } if (o->_class->hasProperty && o->_class->getProperty) { if (o->_class->hasProperty(o, propertyName)) return o->_class->getProperty(o, propertyName, variant); return false; } VOID_TO_NPVARIANT(*variant); return false; }
bool _NPN_SetProperty(NPP, NPObject* o, NPIdentifier propertyName, const NPVariant* variant) { if (o->_class == NPScriptObjectClass) { JavaScriptObject* obj = reinterpret_cast<JavaScriptObject*>(o); RootObject* rootObject = obj->rootObject; if (!rootObject || !rootObject->isValid()) return false; ExecState* exec = rootObject->globalObject()->globalExec(); JSLock lock(false); PrivateIdentifier* i = static_cast<PrivateIdentifier*>(propertyName); if (i->isString) { PutPropertySlot slot; obj->imp->put(exec, identifierFromNPIdentifier(i->value.string), convertNPVariantToValue(exec, variant, rootObject), slot); } else obj->imp->put(exec, i->value.number, convertNPVariantToValue(exec, variant, rootObject)); exec->clearException(); return true; } if (o->_class->setProperty) return o->_class->setProperty(o, propertyName, variant); return false; }
bool _NPN_SetProperty(NPP, NPObject* o, NPIdentifier propertyName, const NPVariant* variant) { if (o->_class == NPScriptObjectClass) { JavaScriptObject* obj = (JavaScriptObject*)o; if (!_isSafeScript(obj)) return false; RootObject* rootObject = obj->rootObject; if (!rootObject || !rootObject->isValid()) return false; ExecState* exec = rootObject->interpreter()->globalExec(); JSLock lock; PrivateIdentifier* i = (PrivateIdentifier*)propertyName; if (i->isString) obj->imp->put(exec, identifierFromNPIdentifier(i->value.string), convertNPVariantToValue(exec, variant)); else obj->imp->put(exec, i->value.number, convertNPVariantToValue(exec, variant)); return true; } if (o->_class->setProperty) return o->_class->setProperty(o, propertyName, variant); return false; }
bool _NPN_Enumerate(NPP, NPObject* o, NPIdentifier** identifier, uint32_t* count) { if (o->_class == NPScriptObjectClass) { JavaScriptObject* obj = reinterpret_cast<JavaScriptObject*>(o); RootObject* rootObject = obj->rootObject; if (!rootObject || !rootObject->isValid()) return false; ExecState* exec = rootObject->globalObject()->globalExec(); JSLock lock(false); PropertyNameArray propertyNames(exec); obj->imp->getPropertyNames(exec, propertyNames); unsigned size = static_cast<unsigned>(propertyNames.size()); // FIXME: This should really call NPN_MemAlloc but that's in WebKit NPIdentifier* identifiers = static_cast<NPIdentifier*>(malloc(sizeof(NPIdentifier) * size)); for (unsigned i = 0; i < size; ++i) identifiers[i] = _NPN_GetStringIdentifier(propertyNames[i].ustring().UTF8String().c_str()); *identifier = identifiers; *count = size; exec->clearException(); return true; } if (NP_CLASS_STRUCT_VERSION_HAS_ENUM(o->_class) && o->_class->enumerate) return o->_class->enumerate(o, identifier, count); return false; }
bool _NPN_RemoveProperty(NPP, NPObject* o, NPIdentifier propertyName) { if (o->_class == NPScriptObjectClass) { JavaScriptObject* obj = (JavaScriptObject*)o; if (!_isSafeScript(obj)) return false; RootObject* rootObject = obj->rootObject; if (!rootObject || !rootObject->isValid()) return false; ExecState* exec = rootObject->interpreter()->globalExec(); PrivateIdentifier* i = (PrivateIdentifier*)propertyName; if (i->isString) { if (!obj->imp->hasProperty(exec, identifierFromNPIdentifier(i->value.string))) return false; } else { if (!obj->imp->hasProperty(exec, i->value.number)) return false; } JSLock lock; if (i->isString) obj->imp->deleteProperty(exec, identifierFromNPIdentifier(i->value.string)); else obj->imp->deleteProperty(exec, i->value.number); return true; } return false; }
bool _NPN_SetProperty(NPP, NPObject* o, NPIdentifier propertyName, const NPVariant* variant) { if (o->_class == NPScriptObjectClass) { JavaScriptObject* obj = reinterpret_cast<JavaScriptObject*>(o); RootObject* rootObject = obj->rootObject; if (!rootObject || !rootObject->isValid()) return false; ExecState* exec = rootObject->globalObject()->globalExec(); JSLockHolder lock(exec); IdentifierRep* i = static_cast<IdentifierRep*>(propertyName); if (i->isString()) { PutPropertySlot slot(obj->imp); obj->imp->methodTable()->put(obj->imp, exec, identifierFromNPIdentifier(exec, i->string()), convertNPVariantToValue(exec, variant, rootObject), slot); } else obj->imp->methodTable()->putByIndex(obj->imp, exec, i->number(), convertNPVariantToValue(exec, variant, rootObject), false); exec->clearException(); return true; } if (o->_class->setProperty) return o->_class->setProperty(o, propertyName, variant); return false; }
bool _NPN_RemoveProperty(NPP, NPObject* o, NPIdentifier propertyName) { if (o->_class == NPScriptObjectClass) { JavaScriptObject* obj = reinterpret_cast<JavaScriptObject*>(o); RootObject* rootObject = obj->rootObject; if (!rootObject || !rootObject->isValid()) return false; ExecState* exec = rootObject->globalObject()->globalExec(); IdentifierRep* i = static_cast<IdentifierRep*>(propertyName); if (i->isString()) { if (!obj->imp->hasProperty(exec, identifierFromNPIdentifier(exec, i->string()))) { exec->clearException(); return false; } } else { if (!obj->imp->hasProperty(exec, i->number())) { exec->clearException(); return false; } } JSLockHolder lock(exec); if (i->isString()) obj->imp->methodTable()->deleteProperty(obj->imp, exec, identifierFromNPIdentifier(exec, i->string())); else obj->imp->methodTable()->deletePropertyByIndex(obj->imp, exec, i->number()); exec->clearException(); return true; } return false; }
bool _NPN_Evaluate(NPP instance, NPObject* o, NPString* s, NPVariant* variant) { if (o->_class == NPScriptObjectClass) { JavaScriptObject* obj = reinterpret_cast<JavaScriptObject*>(o); RootObject* rootObject = obj->rootObject; if (!rootObject || !rootObject->isValid()) return false; // There is a crash in Flash when evaluating a script that destroys the // PluginView, so we destroy it asynchronously. PluginView::keepAlive(instance); ExecState* exec = rootObject->globalObject()->globalExec(); JSLockHolder lock(exec); String scriptString = convertNPStringToUTF16(s); JSValue returnValue = JSC::evaluate(rootObject->globalObject()->globalExec(), makeSource(scriptString), JSC::JSValue()); convertValueToNPVariant(exec, returnValue, variant); exec->clearException(); return true; } VOID_TO_NPVARIANT(*variant); return false; }
bool _NPN_HasMethod(NPP, NPObject* o, NPIdentifier methodName) { if (o->_class == NPScriptObjectClass) { JavaScriptObject* obj = (JavaScriptObject*)o; if (!_isSafeScript(obj)) return false; PrivateIdentifier* i = (PrivateIdentifier*)methodName; if (!i->isString) return false; RootObject* rootObject = obj->rootObject; if (!rootObject || !rootObject->isValid()) return false; ExecState* exec = rootObject->interpreter()->globalExec(); JSLock lock; JSValue* func = obj->imp->get(exec, identifierFromNPIdentifier(i->value.string)); return !func->isUndefined(); } if (o->_class->hasMethod) return o->_class->hasMethod(o, methodName); return false; }
bool _NPN_Evaluate(NPP, NPObject* o, NPString* s, NPVariant* variant) { if (o->_class == NPScriptObjectClass) { JavaScriptObject* obj = reinterpret_cast<JavaScriptObject*>(o); RootObject* rootObject = obj->rootObject; if (!rootObject || !rootObject->isValid()) return false; ExecState* exec = rootObject->globalObject()->globalExec(); JSLock lock(SilenceAssertionsOnly); String scriptString = convertNPStringToUTF16(s); ProtectedPtr<JSGlobalObject> globalObject = rootObject->globalObject(); globalObject->globalData()->timeoutChecker.start(); Completion completion = JSC::evaluate(globalObject->globalExec(), globalObject->globalScopeChain(), makeSource(scriptString), JSC::JSValue()); globalObject->globalData()->timeoutChecker.stop(); ComplType type = completion.complType(); JSValue result; if (type == Normal) { result = completion.value(); if (!result) result = jsUndefined(); } else result = jsUndefined(); convertValueToNPVariant(exec, result, variant); exec->clearException(); return true; } VOID_TO_NPVARIANT(*variant); return false; }
bool _NPN_HasMethod(NPP, NPObject* o, NPIdentifier methodName) { if (o->_class == NPScriptObjectClass) { JavaScriptObject* obj = reinterpret_cast<JavaScriptObject*>(o); PrivateIdentifier* i = static_cast<PrivateIdentifier*>(methodName); if (!i->isString) return false; RootObject* rootObject = obj->rootObject; if (!rootObject || !rootObject->isValid()) return false; ExecState* exec = rootObject->globalObject()->globalExec(); JSLock lock(false); JSValue* func = obj->imp->get(exec, identifierFromNPIdentifier(i->value.string)); exec->clearException(); return !func->isUndefined(); } if (o->_class->hasMethod) return o->_class->hasMethod(o, methodName); return false; }
bool _NPN_Evaluate(NPP, NPObject* o, NPString* s, NPVariant* variant) { if (o->_class == NPScriptObjectClass) { JavaScriptObject* obj = reinterpret_cast<JavaScriptObject*>(o); RootObject* rootObject = obj->rootObject; if (!rootObject || !rootObject->isValid()) return false; ExecState* exec = rootObject->globalObject()->globalExec(); JSLock lock(false); String scriptString = convertNPStringToUTF16(s); rootObject->globalObject()->startTimeoutCheck(); Completion completion = Interpreter::evaluate(rootObject->globalObject()->globalExec(), rootObject->globalObject()->globalScopeChain(), UString(), 1, scriptString); rootObject->globalObject()->stopTimeoutCheck(); ComplType type = completion.complType(); JSValue* result; if (type == Normal) { result = completion.value(); if (!result) result = jsUndefined(); } else result = jsUndefined(); convertValueToNPVariant(exec, result, variant); exec->clearException(); return true; } VOID_TO_NPVARIANT(*variant); return false; }
bool _NPN_Invoke(NPP npp, NPObject* o, NPIdentifier methodName, const NPVariant* args, uint32_t argCount, NPVariant* result) { if (o->_class == NPScriptObjectClass) { JavaScriptObject* obj = (JavaScriptObject*)o; if (!_isSafeScript(obj)) return false; PrivateIdentifier* i = (PrivateIdentifier*)methodName; if (!i->isString) return false; // Special case the "eval" method. if (methodName == _NPN_GetStringIdentifier("eval")) { if (argCount != 1) return false; if (args[0].type != NPVariantType_String) return false; return _NPN_Evaluate(npp, o, (NPString *)&args[0].value.stringValue, result); } // Lookup the function object. RootObject* rootObject = obj->rootObject; if (!rootObject || !rootObject->isValid()) return false; ExecState* exec = rootObject->interpreter()->globalExec(); JSLock lock; JSValue* func = obj->imp->get(exec, identifierFromNPIdentifier(i->value.string)); if (func->isNull()) { NULL_TO_NPVARIANT(*result); return false; } if (func->isUndefined()) { VOID_TO_NPVARIANT(*result); return false; } // Call the function object. JSObject *funcImp = static_cast<JSObject*>(func); JSObject *thisObj = const_cast<JSObject*>(obj->imp); List argList = listFromVariantArgs(exec, args, argCount, rootObject); rootObject->interpreter()->startTimeoutCheck(); JSValue *resultV = funcImp->call (exec, thisObj, argList); rootObject->interpreter()->stopTimeoutCheck(); // Convert and return the result of the function call. convertValueToNPVariant(exec, resultV, result); return true; } if (o->_class->invoke) return o->_class->invoke(o, methodName, args, argCount, result); VOID_TO_NPVARIANT(*result); return true; }
void _NPN_SetException(NPObject* o, const NPUTF8* message) { if (o->_class == NPScriptObjectClass) { JavaScriptObject* obj = (JavaScriptObject*)o; RootObject* rootObject = obj->rootObject; if (!rootObject || !rootObject->isValid()) return; ExecState* exec = rootObject->interpreter()->globalExec(); JSLock lock; throwError(exec, GeneralError, message); } }
bool _NPN_Invoke(NPP npp, NPObject* o, NPIdentifier methodName, const NPVariant* args, uint32_t argCount, NPVariant* result) { if (o->_class == NPScriptObjectClass) { JavaScriptObject* obj = reinterpret_cast<JavaScriptObject*>(o); IdentifierRep* i = static_cast<IdentifierRep*>(methodName); if (!i->isString()) return false; // Special case the "eval" method. if (methodName == _NPN_GetStringIdentifier("eval")) { if (argCount != 1) return false; if (args[0].type != NPVariantType_String) return false; return _NPN_Evaluate(npp, o, const_cast<NPString*>(&args[0].value.stringValue), result); } // Look up the function object. RootObject* rootObject = obj->rootObject; if (!rootObject || !rootObject->isValid()) return false; ExecState* exec = rootObject->globalObject()->globalExec(); JSLock lock(SilenceAssertionsOnly); JSValue function = obj->imp->get(exec, identifierFromNPIdentifier(i->string())); CallData callData; CallType callType = function.getCallData(callData); if (callType == CallTypeNone) return false; // Call the function object. MarkedArgumentBuffer argList; getListFromVariantArgs(exec, args, argCount, rootObject, argList); ProtectedPtr<JSGlobalObject> globalObject = rootObject->globalObject(); globalObject->globalData()->timeoutChecker.start(); JSValue resultV = JSC::call(exec, function, callType, callData, obj->imp, argList); globalObject->globalData()->timeoutChecker.stop(); // Convert and return the result of the function call. convertValueToNPVariant(exec, resultV, result); exec->clearException(); return true; } if (o->_class->invoke) return o->_class->invoke(o, methodName, args, argCount, result); VOID_TO_NPVARIANT(*result); return true; }
bool _NPN_GetProperty(NPP, NPObject* o, NPIdentifier propertyName, NPVariant* variant) { if (o->_class == NPScriptObjectClass) { JavaScriptObject* obj = (JavaScriptObject*)o; if (!_isSafeScript(obj)) return false; RootObject* rootObject = obj->rootObject; if (!rootObject || !rootObject->isValid()) return false; ExecState* exec = rootObject->interpreter()->globalExec(); PrivateIdentifier* i = (PrivateIdentifier*)propertyName; JSLock lock; JSValue *result; if (i->isString) result = obj->imp->get(exec, identifierFromNPIdentifier(i->value.string)); else result = obj->imp->get(exec, i->value.number); if (result->isNull()) { NULL_TO_NPVARIANT(*variant); return false; } if (result->isUndefined()) { VOID_TO_NPVARIANT(*variant); return false; } convertValueToNPVariant(exec, result, variant); return true; } if (o->_class->hasProperty && o->_class->getProperty) { if (o->_class->hasProperty(o, propertyName)) return o->_class->getProperty(o, propertyName, variant); return false; } VOID_TO_NPVARIANT(*variant); return false; }
bool _NPN_Evaluate(NPP, NPObject* o, NPString* s, NPVariant* variant) { if (o->_class == NPScriptObjectClass) { JavaScriptObject* obj = (JavaScriptObject*)o; if (!_isSafeScript(obj)) return false; RootObject* rootObject = obj->rootObject; if (!rootObject || !rootObject->isValid()) return false; ExecState* exec = rootObject->interpreter()->globalExec(); JSLock lock; NPUTF16* scriptString; unsigned int UTF16Length; convertNPStringToUTF16(s, &scriptString, &UTF16Length); // requires free() of returned memory rootObject->interpreter()->startTimeoutCheck(); Completion completion = rootObject->interpreter()->evaluate(UString(), 0, UString((const UChar*)scriptString,UTF16Length)); rootObject->interpreter()->stopTimeoutCheck(); ComplType type = completion.complType(); JSValue* result; if (type == Normal) { result = completion.value(); if (!result) result = jsUndefined(); } else result = jsUndefined(); free(scriptString); convertValueToNPVariant(exec, result, variant); return true; } VOID_TO_NPVARIANT(*variant); return false; }
bool _NPN_InvokeDefault(NPP, NPObject* o, const NPVariant* args, uint32_t argCount, NPVariant* result) { if (o->_class == NPScriptObjectClass) { JavaScriptObject* obj = reinterpret_cast<JavaScriptObject*>(o); VOID_TO_NPVARIANT(*result); // Lookup the function object. RootObject* rootObject = obj->rootObject; if (!rootObject || !rootObject->isValid()) return false; ExecState* exec = rootObject->globalObject()->globalExec(); JSLock lock(SilenceAssertionsOnly); // Call the function object. JSValue function = obj->imp; CallData callData; CallType callType = function.getCallData(callData); if (callType == CallTypeNone) return false; MarkedArgumentBuffer argList; getListFromVariantArgs(exec, args, argCount, rootObject, argList); ProtectedPtr<JSGlobalObject> globalObject = rootObject->globalObject(); globalObject->globalData()->timeoutChecker.start(); JSValue resultV = JSC::call(exec, function, callType, callData, function, argList); globalObject->globalData()->timeoutChecker.stop(); // Convert and return the result of the function call. convertValueToNPVariant(exec, resultV, result); exec->clearException(); return true; } if (o->_class->invokeDefault) return o->_class->invokeDefault(o, args, argCount, result); VOID_TO_NPVARIANT(*result); return true; }
bool _NPN_Construct(NPP, NPObject* o, const NPVariant* args, uint32_t argCount, NPVariant* result) { if (o->_class == NPScriptObjectClass) { JavaScriptObject* obj = reinterpret_cast<JavaScriptObject*>(o); VOID_TO_NPVARIANT(*result); // Lookup the constructor object. RootObject* rootObject = obj->rootObject; if (!rootObject || !rootObject->isValid()) return false; ExecState* exec = rootObject->globalObject()->globalExec(); JSLock lock(SilenceAssertionsOnly); // Call the constructor object. JSValue constructor = obj->imp; ConstructData constructData; ConstructType constructType = constructor.getConstructData(constructData); if (constructType == ConstructTypeNone) return false; MarkedArgumentBuffer argList; getListFromVariantArgs(exec, args, argCount, rootObject, argList); ProtectedPtr<JSGlobalObject> globalObject = rootObject->globalObject(); globalObject->globalData()->timeoutChecker.start(); JSValue resultV = JSC::construct(exec, constructor, constructType, constructData, argList); globalObject->globalData()->timeoutChecker.stop(); // Convert and return the result. convertValueToNPVariant(exec, resultV, result); exec->clearException(); return true; } if (NP_CLASS_STRUCT_VERSION_HAS_CTOR(o->_class) && o->_class->construct) return o->_class->construct(o, args, argCount, result); return false; }
bool _NPN_InvokeDefault(NPP, NPObject* o, const NPVariant* args, uint32_t argCount, NPVariant* result) { if (o->_class == NPScriptObjectClass) { JavaScriptObject* obj = (JavaScriptObject*)o; if (!_isSafeScript(obj)) return false; VOID_TO_NPVARIANT(*result); // Lookup the function object. RootObject* rootObject = obj->rootObject; if (!rootObject || !rootObject->isValid()) return false; ExecState* exec = rootObject->interpreter()->globalExec(); JSLock lock; // Call the function object. JSObject *funcImp = static_cast<JSObject*>(obj->imp); if (!funcImp->implementsCall()) return false; List argList = listFromVariantArgs(exec, args, argCount, rootObject); rootObject->interpreter()->startTimeoutCheck(); JSValue *resultV = funcImp->call (exec, funcImp, argList); rootObject->interpreter()->stopTimeoutCheck(); // Convert and return the result of the function call. convertValueToNPVariant(exec, resultV, result); return true; } if (o->_class->invokeDefault) return o->_class->invokeDefault(o, args, argCount, result); VOID_TO_NPVARIANT(*result); return true; }