Esempio n. 1
0
static EncodedJSValue JSC_HOST_CALL constructImage(ExecState* exec)
{
    JSImageConstructor* jsConstructor = jsCast<JSImageConstructor*>(exec->callee());
    Document* document = jsConstructor->document();
    if (!document)
        return throwVMError(exec, createReferenceError(exec, "Image constructor associated document is unavailable"));

    // Calling toJS on the document causes the JS document wrapper to be
    // added to the window object. This is done to ensure that JSDocument::visit
    // will be called, which will cause the image element to be marked if necessary.
    toJS(exec, jsConstructor->globalObject(), document);
    int width;
    int height;
    int* optionalWidth = 0;
    int* optionalHeight = 0;
    if (exec->argumentCount() > 0) {
        width = exec->argument(0).toInt32(exec);
        optionalWidth = &width;
    }
    if (exec->argumentCount() > 1) {
        height = exec->argument(1).toInt32(exec);
        optionalHeight = &height;
    }

    return JSValue::encode(asObject(toJS(exec, jsConstructor->globalObject(),
        HTMLImageElement::createForJSConstructor(*document, optionalWidth, optionalHeight))));
}
static JSObject* constructImage(ExecState* exec, JSObject* constructor, const ArgList& args)
{
    JSImageConstructor* jsConstructor = static_cast<JSImageConstructor*>(constructor);
    Document* document = jsConstructor->document();
    if (!document)
        return throwError(exec, ReferenceError, "Image constructor associated document is unavailable");

    // Calling toJS on the document causes the JS document wrapper to be
    // added to the window object. This is done to ensure that JSDocument::markChildren
    // will be called, which will cause the image element to be marked if necessary.
    toJS(exec, jsConstructor->globalObject(), document);
    int width;
    int height;
    int* optionalWidth = 0;
    int* optionalHeight = 0;
    if (args.size() > 0) {
        width = args.at(0).toInt32(exec);
        optionalWidth = &width;
    }
    if (args.size() > 1) {
        height = args.at(1).toInt32(exec);
        optionalHeight = &height;
    }

    return asObject(toJS(exec, jsConstructor->globalObject(),
        HTMLImageElement::createForJSConstructor(document, optionalWidth, optionalHeight)));
}