JSValue JSCanvasRenderingContext2D::webkitLineDash(ExecState* exec) const
{
    CanvasRenderingContext2D* context = static_cast<CanvasRenderingContext2D*>(impl());
    const Vector<float>& dash = context->getLineDash();

    MarkedArgumentBuffer list;
    Vector<float>::const_iterator end = dash.end();
    for (Vector<float>::const_iterator it = dash.begin(); it != end; ++it)
        list.append(JSValue(*it));
    return constructArray(exec, 0, globalObject(), list);
}
Example #2
0
Bindings::RootObject* ScriptController::bindingRootObject()
{
    if (!canExecuteScripts(NotAboutToExecuteScript))
        return 0;

    if (!m_bindingRootObject) {
        JSLockHolder lock(JSDOMWindowBase::commonVM());
        m_bindingRootObject = Bindings::RootObject::create(0, globalObject(pluginWorld()));
    }
    return m_bindingRootObject.get();
}
JSValue JSWebGLRenderingContextBase::getSupportedExtensions(ExecState& state)
{
    WebGLRenderingContextBase& context = wrapped();
    if (context.isContextLost())
        return jsNull();
    Vector<String> value = context.getSupportedExtensions();
    MarkedArgumentBuffer list;
    for (size_t ii = 0; ii < value.size(); ++ii)
        list.append(jsStringWithCache(&state, value[ii]));
    return constructArray(&state, 0, globalObject(), list);
}
Bindings::RootObject* ScriptController::bindingRootObject()
{
    if (!canExecuteScripts(NotAboutToExecuteScript))
        return 0;

    if (!m_bindingRootObject) {
        JSLock lock(SilenceAssertionsOnly);
        m_bindingRootObject = Bindings::RootObject::create(0, globalObject(pluginWorld()));
    }
    return m_bindingRootObject.get();
}
Example #5
0
JSValue JSSubtleCrypto::digest(ExecState* exec)
{
    if (exec->argumentCount() < 2)
        return exec->vm().throwException(exec, createNotEnoughArgumentsError(exec));

    auto algorithm = createAlgorithmFromJSValue(exec, exec->uncheckedArgument(0));
    if (!algorithm) {
        ASSERT(exec->hadException());
        return jsUndefined();
    }

    auto parameters = JSCryptoAlgorithmDictionary::createParametersForDigest(exec, algorithm->identifier(), exec->uncheckedArgument(0));
    if (!parameters) {
        ASSERT(exec->hadException());
        return jsUndefined();
    }

    CryptoOperationData data;
    if (!cryptoOperationDataFromJSValue(exec, exec->uncheckedArgument(1), data)) {
        ASSERT(exec->hadException());
        return jsUndefined();
    }

    JSPromiseDeferred* promiseDeferred = JSPromiseDeferred::create(exec, globalObject());
    DeferredWrapper wrapper(exec, globalObject(), promiseDeferred);
    auto successCallback = [wrapper](const Vector<uint8_t>& result) mutable {
        wrapper.resolve(result);
    };
    auto failureCallback = [wrapper]() mutable {
        wrapper.reject(nullptr);
    };

    ExceptionCode ec = 0;
    algorithm->digest(*parameters, data, WTF::move(successCallback), WTF::move(failureCallback), ec);
    if (ec) {
        setDOMException(exec, ec);
        return jsUndefined();
    }

    return promiseDeferred->promise();
}
Example #6
0
JSValue JSCallbackData::invokeCallback(MarkedArgumentBuffer& args, bool* raisedException)
{
    ASSERT(callback());
    ASSERT(globalObject());

    ExecState* exec = globalObject()->globalExec();
    JSValue function = callback()->get(exec, Identifier(exec, "handleEvent"));

    CallData callData;
    CallType callType = getCallData(function, callData);
    if (callType == CallTypeNone) {
        callType = callback()->methodTable()->getCallData(callback(), callData);
        if (callType == CallTypeNone)
            return JSValue();
        function = callback();
    }
    
    globalObject()->globalData().timeoutChecker.start();
    ScriptExecutionContext* context = globalObject()->scriptExecutionContext();
    // We will fail to get the context if the frame has been detached.
    if (!context)
        return JSValue();

    bool contextIsDocument = context->isDocument();
    JSValue result = contextIsDocument
        ? JSMainThreadExecState::call(exec, function, callType, callData, callback(), args)
        : JSC::call(exec, function, callType, callData, callback(), args);
    globalObject()->globalData().timeoutChecker.stop();

    if (contextIsDocument)
        Document::updateStyleForAllDocuments();

    if (exec->hadException()) {
        reportCurrentException(exec);
        if (raisedException)
            *raisedException = true;
        return result;
    }
    
    return result;
}
Example #7
0
QScriptValue PluginsScript::call(QString sScript, QString sFunctionName, QScriptValueList valuelist,QString sExtra)
{
    // TODO check if function
    QScriptValue script = evaluate(sScript);
    if(!script.isError())
    {
        QScriptValue detect=globalObject().property(sFunctionName);
        if(!detect.isError())
        {

            QScriptValue result=detect.call(script,valuelist);
            if(!result.isError())
            {
                return result;
            }
            else
            {
                if(sExtra!="")
                {
                    emit appendError(QString("%1: %2").arg(sExtra).arg(result.toString()));
                }
                else
                {
                    emit appendError(QString("%1").arg(result.toString()));
                }
            }
        }
        else
        {
            if(sExtra!="")
            {
                emit appendError(QString("%1: %2").arg(sExtra).arg(detect.toString()));
            }
            else
            {
                emit appendError(QString("%1").arg(detect.toString()));
            }
        }
    }
    else
    {
        if(sExtra!="")
        {
            emit appendError(QString("%1: %2").arg(sExtra).arg(script.toString()));
        }
        else
        {
            emit appendError(QString("%1").arg(script.toString()));
        }
    }

    return 0;
}
Example #8
0
JSValue JSSVGMatrix::inverse(ExecState* exec)
{
    AffineTransform imp(*impl());

    SVGElement* context = JSSVGContextCache::svgContextForDOMObject(this);
    JSValue result = toJS(exec, globalObject(), JSSVGStaticPODTypeWrapper<AffineTransform>::create(imp.inverse()).get(), context);

    if (!imp.isInvertible())
        setDOMException(exec, SVGException::SVG_MATRIX_NOT_INVERTABLE);

    return result;
}
Example #9
0
JSValue JSXSLTProcessor::transformToFragment(ExecState* exec)
{
    JSValue nodeVal = exec->argument(0);
    JSValue docVal = exec->argument(1);
    if (nodeVal.inherits(&JSNode::s_info) && docVal.inherits(&JSDocument::s_info)) {
        WebCore::Node* node = static_cast<JSNode*>(asObject(nodeVal))->impl();
        Document* doc = static_cast<Document*>(static_cast<JSDocument*>(asObject(docVal))->impl());
        return toJS(exec, globalObject(), impl()->transformToFragment(node, doc).get());
    }
    // Throw exception?
    return jsUndefined();
}
JSValue JSWebGLRenderingContextBase::getExtension(ExecState& state)
{
    if (state.argumentCount() < 1)
        return state.vm().throwException(&state, createNotEnoughArgumentsError(&state));
    
    WebGLRenderingContextBase& context = wrapped();
    const String name = state.uncheckedArgument(0).toString(&state)->value(&state);
    if (state.hadException())
        return jsUndefined();
    WebGLExtension* extension = context.getExtension(name);
    return toJS(&state, globalObject(), extension);
}
JSValue JSWebGLRenderingContextBase::getExtension(ExecState* exec)
{
    if (exec->argumentCount() < 1)
        return exec->vm().throwException(exec, createNotEnoughArgumentsError(exec));
    
    WebGLRenderingContextBase& context = impl();
    const String name = exec->uncheckedArgument(0).toString(exec)->value(exec);
    if (exec->hadException())
        return jsUndefined();
    WebGLExtension* extension = context.getExtension(name);
    return toJS(exec, globalObject(), extension);
}
void http_script_engine::initialize_default()
{
	QScriptValue global_object = globalObject();
	global_object.setProperty("load",newFunction(loadScripts, 1));

	post_data_list_class *pdlc = new post_data_list_class(this);
	global_object.setProperty("post_data_list", pdlc->constructor());

	setDefaultPrototype(qMetaTypeId<http_data_list*>(), pdlc->newInstance());

	global_object.setProperty("code_tool", newQObject(_code_tool));
}
Example #13
0
JSArray* JSBoundFunction::boundArgsCopy(ExecState* exec)
{
    VM& vm = exec->vm();
    auto scope = DECLARE_THROW_SCOPE(vm);
    JSArray* result = constructEmptyArray(exec, nullptr, globalObject());
    RETURN_IF_EXCEPTION(scope, nullptr);
    for (unsigned i = 0; i < m_boundArgs->length(); ++i) {
        result->push(exec, m_boundArgs->getIndexQuickly(i));
        RETURN_IF_EXCEPTION(scope, nullptr);
    }
    return result;
}
JSValue JSWebGLRenderingContext::getExtension(ExecState* exec)
{
    if (exec->argumentCount() < 1)
        return throwSyntaxError(exec);

    WebGLRenderingContext* context = static_cast<WebGLRenderingContext*>(impl());
    const String& name = ustringToString(exec->argument(0).toString(exec));
    if (exec->hadException())
        return jsUndefined();
    WebGLExtension* extension = context->getExtension(name);
    return toJS(exec, globalObject(), extension);
}
Example #15
0
JSValue JSWorkerContext::openDatabaseSync(ExecState* exec)
{
    if (exec->argumentCount() < 4) {
        setDOMException(exec, SYNTAX_ERR);
        return jsUndefined();
    }

    String name = ustringToString(exec->argument(0).toString(exec));
    if (exec->hadException())
        return jsUndefined();

    String version = ustringToString(exec->argument(1).toString(exec));
    if (exec->hadException())
        return jsUndefined();

    String displayName = ustringToString(exec->argument(2).toString(exec));
    if (exec->hadException())
        return jsUndefined();

    // exec->argument(3) = estimated size
    unsigned long estimatedSize = exec->argument(3).toUInt32(exec);
    if (exec->hadException())
        return jsUndefined();

    RefPtr<DatabaseCallback> creationCallback;
    if (exec->argumentCount() >= 5) {
        if (!exec->argument(4).isObject()) {
            setDOMException(exec, TYPE_MISMATCH_ERR);
            return jsUndefined();
        }

        creationCallback = JSDatabaseCallback::create(asObject(exec->argument(4)), globalObject());
    }

    ExceptionCode ec = 0;
    JSValue result = toJS(exec, globalObject(), WTF::getPtr(impl()->openDatabaseSync(name, version, displayName, estimatedSize, creationCallback.release(), ec)));

    setDOMException(exec, ec);
    return result;
}
JSValue JSHTMLAllCollection::item(ExecState& state)
{
    VM& vm = state.vm();
    auto scope = DECLARE_THROW_SCOPE(vm);

    if (UNLIKELY(state.argumentCount() < 1))
        return throwException(&state, scope, createNotEnoughArgumentsError(&state));

    String argument = state.uncheckedArgument(0).toWTFString(&state);
    if (Optional<uint32_t> index = parseIndex(*argument.impl()))
        return toJS(&state, globalObject(), wrapped().item(index.value()));
    return namedItems(state, this, Identifier::fromString(&state, argument));
}
JSValue JSDocument::createTouchList(ExecState& state)
{
    auto touchList = TouchList::create();

    for (size_t i = 0; i < state.argumentCount(); ++i) {
        auto* item = JSTouch::toWrapped(state.uncheckedArgument(i));
        if (!item)
            return JSValue::decode(throwArgumentTypeError(state, i, "touches", "Document", "createTouchList", "Touch"));

        touchList->append(*item);
    }
    return toJSNewlyCreated(&state, globalObject(), WTFMove(touchList));
}
JSValue JSInternals::userPreferredLanguages(ExecState* exec) const
{
    Internals* imp = static_cast<Internals*>(impl());
    const Vector<String> languages = imp->userPreferredLanguages();
    if (languages.isEmpty())
        return jsNull();
    
    MarkedArgumentBuffer array;
    Vector<String>::const_iterator end = languages.end();
    for (Vector<String>::const_iterator it = languages.begin(); it != end; ++it)
        array.append(jsString(exec, stringToUString(*it)));
    return constructArray(exec, globalObject(), array);
}
Example #19
0
JSValue JSXSLTProcessor::transformToDocument(ExecState* exec)
{
    JSValue nodeVal = exec->argument(0);
    if (nodeVal.inherits(&JSNode::s_info)) {
        JSNode* node = static_cast<JSNode*>(asObject(nodeVal));
        RefPtr<Document> resultDocument = impl()->transformToDocument(node->impl());
        if (resultDocument)
            return toJS(exec, globalObject(), resultDocument.get());
        return jsUndefined();
    }
    // Throw exception?
    return jsUndefined();
}
Example #20
0
JSValue JSHistory::state(ExecState *exec) const
{
    History* history = static_cast<History*>(impl());

    JSValue cachedValue = m_state.get();
    if (!cachedValue.isEmpty() && !history->stateChanged())
        return cachedValue;

    RefPtr<SerializedScriptValue> serialized = history->state();
    JSValue result = serialized ? serialized->deserialize(exec, globalObject(), 0) : jsNull();
    const_cast<JSHistory*>(this)->m_state.set(exec->vm(), this, result);
    return result;
}
Example #21
0
void GMathScriptEngine::RegisterVariable( GParamString* pName, GParamNum* pParamNum )
{
	QString name = pName->StringValue();
	double val = pParamNum->DoubleValue();
	if(name != "")
		globalObject().setProperty(name, newVariant(val));

	m_ParamName_ParamNum.insert(pName, pParamNum);
	UpdateAllVariableNames();

	// when renaming, we update the variable names
	connect(pName, SIGNAL(ValueUpdated(QString)), this, SLOT(UpdateAllVariableNames()));
}
JSValue JSWebGLRenderingContextBase::getAttachedShaders(ExecState* exec)
{
    if (exec->argumentCount() < 1)
        return exec->vm().throwException(exec, createNotEnoughArgumentsError(exec));
    ExceptionCode ec = 0;
    WebGLRenderingContextBase& context = impl();
    WebGLProgram* program = JSWebGLProgram::toWrapped(exec->uncheckedArgument(0));
    if (!program && !exec->uncheckedArgument(0).isUndefinedOrNull())
        return throwTypeError(exec);
    Vector<RefPtr<WebGLShader>> shaders;
    bool succeed = context.getAttachedShaders(program, shaders, ec);
    if (ec) {
        setDOMException(exec, ec);
        return jsNull();
    }
    if (!succeed)
        return jsNull();
    JSC::MarkedArgumentBuffer list;
    for (size_t ii = 0; ii < shaders.size(); ++ii)
        list.append(toJS(exec, globalObject(), shaders[ii].get()));
    return constructArray(exec, 0, globalObject(), list);
}
Example #23
0
void RootObject::gcUnprotect(JSObject* jsObject)
{
    ASSERT(m_isValid);
    
    if (!jsObject)
        return;

    if (m_protectCountSet.count(jsObject) == 1) {
        JSC::JSLockHolder holder(&globalObject()->vm());
        JSC::gcUnprotect(jsObject);
    }
    m_protectCountSet.remove(jsObject);
}
JSValue JSCSSStyleDeclaration::getPropertyCSSValue(ExecState* exec)
{
    const String& propertyName(ustringToString(exec->argument(0).toString(exec)->value(exec)));
    if (exec->hadException())
        return jsUndefined();

    RefPtr<CSSValue> cssValue = impl()->getPropertyCSSValue(propertyName);
    if (!cssValue)
        return jsNull();

    currentWorld(exec)->m_cssValueRoots.add(cssValue.get(), root(impl())); // Balanced by JSCSSValueOwner::finalize().
    return toJS(exec, globalObject(), WTF::getPtr(cssValue));
}
JSValue JSSQLTransactionSync::executeSql(ExecState* exec)
{
    if (!exec->argumentCount()) {
        setDOMException(exec, SYNTAX_ERR);
        return jsUndefined();
    }

    String sqlStatement = ustringToString(exec->argument(0).toString(exec));
    if (exec->hadException())
        return jsUndefined();

    // Now assemble the list of SQL arguments
    Vector<SQLValue> sqlValues;
    if (!exec->argument(1).isUndefinedOrNull()) {
        JSObject* object = exec->argument(1).getObject();
        if (!object) {
            setDOMException(exec, TYPE_MISMATCH_ERR);
            return jsUndefined();
        }

        JSValue lengthValue = object->get(exec, exec->propertyNames().length);
        if (exec->hadException())
            return jsUndefined();
        unsigned length = lengthValue.toUInt32(exec);
        if (exec->hadException())
            return jsUndefined();

        for (unsigned i = 0 ; i < length; ++i) {
            JSValue value = object->get(exec, i);
            if (exec->hadException())
                return jsUndefined();

            if (value.isUndefinedOrNull())
                sqlValues.append(SQLValue());
            else if (value.isNumber())
                sqlValues.append(value.uncheckedGetNumber());
            else {
                // Convert the argument to a string and append it
                sqlValues.append(ustringToString(value.toString(exec)));
                if (exec->hadException())
                    return jsUndefined();
            }
        }
    }

    ExceptionCode ec = 0;
    JSValue result = toJS(exec, globalObject(), WTF::getPtr(m_impl->executeSQL(sqlStatement, sqlValues, ec)));
    setDOMException(exec, ec);

    return result;
}
Example #26
0
JSValue JSDocument::location(ExecState* exec) const
{
    Frame* frame = static_cast<Document*>(impl())->frame();
    if (!frame)
        return jsNull();

    Location* location = frame->domWindow()->location();
    if (DOMObject* wrapper = getCachedDOMObjectWrapper(exec, location))
        return wrapper;

    JSLocation* jsLocation = new (exec) JSLocation(getDOMStructure<JSLocation>(exec, globalObject()), globalObject(), location);
    cacheDOMObjectWrapper(exec, location, jsLocation);
    return jsLocation;
}
JSValue JSDocument::location(ExecState* exec) const
{
    Frame* frame = static_cast<Document*>(impl())->frame();
    if (!frame)
        return jsNull();

    Location* location = frame->domWindow()->location();
    if (JSDOMWrapper* wrapper = getCachedWrapper(currentWorld(exec), location))
        return wrapper;

    JSLocation* jsLocation = JSLocation::create(getDOMStructure<JSLocation>(exec, globalObject()), globalObject(), location);
    cacheWrapper(currentWorld(exec), location, jsLocation);
    return jsLocation;
}
JSValue JSSVGPathSegList::appendItem(ExecState* exec, const ArgList& args)
{
    ExceptionCode ec = 0;
    SVGPathSeg* newItem = toSVGPathSeg(args.at(0));

    SVGPathSegList* list = impl();
    SVGElement* context = JSSVGContextCache::svgContextForDOMObject(this);

    JSValue result = toJS(exec, globalObject(), WTF::getPtr(list->appendItem(newItem, ec)), context);
    setDOMException(exec, ec);

    JSSVGContextCache::propagateSVGDOMChange(this, list->associatedAttributeName());
    return result;
}
Example #29
0
JSValue JSSVGMatrix::rotateFromVector(ExecState* exec)
{
    AffineTransform imp(*impl());

    float x = exec->argument(0).toFloat(exec);
    float y = exec->argument(1).toFloat(exec);

    SVGElement* context = JSSVGContextCache::svgContextForDOMObject(this);
    JSValue result = toJS(exec, globalObject(), JSSVGStaticPODTypeWrapper<AffineTransform>::create(imp.rotateFromVector(x, y)).get(), context);

    if (x == 0.0 || y == 0.0)
        setDOMException(exec, SVGException::SVG_INVALID_VALUE_ERR);

    return result;
}
JSValue JSWebGLRenderingContext::getAttachedShaders(ExecState* exec)
{
    if (exec->argumentCount() < 1)
        return throwSyntaxError(exec);
    ExceptionCode ec = 0;
    WebGLRenderingContext* context = static_cast<WebGLRenderingContext*>(impl());
    if (exec->argumentCount() > 0 && !exec->argument(0).isUndefinedOrNull() && !exec->argument(0).inherits(&JSWebGLProgram::s_info))
        return throwTypeError(exec);
    WebGLProgram* program = toWebGLProgram(exec->argument(0));
    if (exec->hadException())
        return jsNull();
    Vector<RefPtr<WebGLShader> > shaders;
    bool succeed = context->getAttachedShaders(program, shaders, ec);
    if (ec) {
        setDOMException(exec, ec);
        return jsNull();
    }
    if (!succeed)
        return jsNull();
    MarkedArgumentBuffer list;
    for (size_t ii = 0; ii < shaders.size(); ++ii)
        list.append(toJS(exec, globalObject(), shaders[ii].get()));
    return constructArray(exec, globalObject(), list);
}