Beispiel #1
0
bool NPRuntimeObjectMap::evaluate(NPObject* npObject, const String&scriptString, NPVariant* result)
{
    ProtectedPtr<JSGlobalObject> globalObject = this->globalObject();
    if (!globalObject)
        return false;

    ExecState* exec = globalObject->globalExec();
    
    JSLock lock(SilenceAssertionsOnly);
    JSValue thisValue = getOrCreateJSObject(globalObject, npObject);

    globalObject->globalData()->timeoutChecker.start();
    Completion completion = JSC::evaluate(exec, globalObject->globalScopeChain(), makeSource(UString(scriptString.impl())), thisValue);
    globalObject->globalData()->timeoutChecker.stop();

    ComplType completionType = completion.complType();

    JSValue resultValue;
    if (completionType == Normal) {
        resultValue = completion.value();
        if (!resultValue)
            resultValue = jsUndefined();
    } else
        resultValue = jsUndefined();

    exec->clearException();
    
    convertJSValueToNPVariant(exec, resultValue, *result);
    return true;
}
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_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;
}
Beispiel #4
0
void WorkerScriptController::initScript()
{
    ASSERT(!m_workerContextWrapper);

    JSLock lock(SilenceAssertionsOnly);

    // Explicitly protect the global object's prototype so it isn't collected
    // when we allocate the global object. (Once the global object is fully
    // constructed, it can mark its own prototype.)
    RefPtr<Structure> workerContextPrototypeStructure = JSWorkerContextPrototype::createStructure(jsNull());
    ProtectedPtr<JSWorkerContextPrototype> workerContextPrototype = new (m_globalData.get()) JSWorkerContextPrototype(0, workerContextPrototypeStructure.release());

    if (m_workerContext->isDedicatedWorkerContext()) {
        RefPtr<Structure> dedicatedContextPrototypeStructure = JSDedicatedWorkerContextPrototype::createStructure(workerContextPrototype);
        ProtectedPtr<JSDedicatedWorkerContextPrototype> dedicatedContextPrototype = new (m_globalData.get()) JSDedicatedWorkerContextPrototype(0, dedicatedContextPrototypeStructure.release());
        RefPtr<Structure> structure = JSDedicatedWorkerContext::createStructure(dedicatedContextPrototype);

        m_workerContextWrapper = new (m_globalData.get()) JSDedicatedWorkerContext(structure.release(), m_workerContext->toDedicatedWorkerContext());
        workerContextPrototype->putAnonymousValue(0, m_workerContextWrapper);
        dedicatedContextPrototype->putAnonymousValue(0, m_workerContextWrapper);
#if ENABLE(SHARED_WORKERS)
    } else {
        ASSERT(m_workerContext->isSharedWorkerContext());
        RefPtr<Structure> sharedContextPrototypeStructure = JSSharedWorkerContextPrototype::createStructure(workerContextPrototype);
        ProtectedPtr<JSSharedWorkerContextPrototype> sharedContextPrototype = new (m_globalData.get()) JSSharedWorkerContextPrototype(0, sharedContextPrototypeStructure.release());
        RefPtr<Structure> structure = JSSharedWorkerContext::createStructure(sharedContextPrototype);

        m_workerContextWrapper = new (m_globalData.get()) JSSharedWorkerContext(structure.release(), m_workerContext->toSharedWorkerContext());
        workerContextPrototype->putAnonymousValue(0, m_workerContextWrapper);
        sharedContextPrototype->putAnonymousValue(0, m_workerContextWrapper);
#endif
    }
}
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 = 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;
}
Beispiel #7
0
JSValue* JSLazyEventListener::eventParameterName() const
{
    static ProtectedPtr<JSValue> eventString = jsString(window()->globalExec(), "event");
    return eventString.get();
}
Beispiel #8
0
JSValue* JSLazyEventListener::eventParameterName() const
{
    static ProtectedPtr<JSValue> eventString = jsString("event");
    return eventString.get();
}
Beispiel #9
0
void cylinder(ProtectedPtr<Mesh> mesh, float diameter, float length, int32_t segments, int32_t stacks) {
    float radius = diameter * 0.5;

    float delta_angle = (kmPI * 2.0) / (float) segments;
    float delta_height = length / (float) stacks;
    int offset = 0;

    auto smi = mesh->new_submesh();
    auto* buffer = mesh->submesh(smi);

    for(auto i = 0; i <= stacks; ++i) {
        for(auto j = 0; j <= segments; ++j) {
            float x0 = radius * cosf(delta_angle * j);
            float z0 = radius * sinf(delta_angle * j);

            kglt::Vec3 new_point(x0, delta_height * i, z0);
            kglt::Vec3 new_normal = kglt::Vec3(x0, 0, z0).normalized();
            kglt::Vec2 new_uv = kglt::Vec2(j / (float) segments, i / (float) stacks);

            mesh->shared_data().position(new_point);
            mesh->shared_data().diffuse(kglt::Colour::WHITE);
            mesh->shared_data().normal(new_normal);
            mesh->shared_data().tex_coord0(new_uv);
            mesh->shared_data().move_next();

            if(i != stacks) {
                buffer->index_data().index(offset + segments + 1);
                buffer->index_data().index(offset);
                buffer->index_data().index(offset + segments);
                buffer->index_data().index(offset + segments + 1);
                buffer->index_data().index(offset + 1);
                buffer->index_data().index(offset);
            }
            ++offset;
        }
    }

    // Now cap the cylinder
    auto center_index = offset;

    // Add a central point at the base
    mesh->shared_data().position(kglt::Vec3());
    mesh->shared_data().normal(kglt::Vec3(0, -1, 0));
    mesh->shared_data().tex_coord0(kglt::Vec2());
    mesh->shared_data().move_next();
    ++offset;

    for(auto j = 0; j <= segments; ++j) {
        float x0 = cosf(j * delta_angle);
        float z0 = sinf(j * delta_angle);

        kglt::Vec3 new_point(x0 * radius, 0, z0 * radius);
        kglt::Vec3 new_normal(0, -1, 0);
        kglt::Vec2 new_uv(x0, z0);

        mesh->shared_data().position(new_point);
        mesh->shared_data().normal(new_normal);
        mesh->shared_data().tex_coord0(new_uv);
        mesh->shared_data().move_next();

        if(j != segments) {
            buffer->index_data().index(center_index);
            buffer->index_data().index(offset);
            buffer->index_data().index(offset + 1);
        }
    }

    center_index = offset;
    // Add a central point at the top
    mesh->shared_data().position(kglt::Vec3(0, length, 0));
    mesh->shared_data().normal(kglt::Vec3(0, 1, 0));
    mesh->shared_data().tex_coord0(kglt::Vec2());
    mesh->shared_data().move_next();
    ++offset;

    for(auto j = 0; j <= segments; ++j) {
        float x0 = cosf(j * delta_angle);
        float z0 = sinf(j * delta_angle);

        kglt::Vec3 new_point(x0 * radius, length, z0 * radius);
        kglt::Vec3 new_normal(0, 1, 0);
        kglt::Vec2 new_uv(x0, z0);

        mesh->shared_data().position(new_point);
        mesh->shared_data().normal(new_normal);
        mesh->shared_data().tex_coord0(new_uv);
        mesh->shared_data().move_next();

        if(j != segments) {
            buffer->index_data().index(center_index);
            buffer->index_data().index(offset + 1);
            buffer->index_data().index(offset);
        }
    }

    mesh->shared_data().done();
    buffer->index_data().done();
}