EncodedJSValue JSC_HOST_CALL JSPromiseConstructorFuncResolve(ExecState* exec)
{
    if (!exec->argumentCount())
        return throwVMError(exec, createTypeError(exec, "Expected at least one argument"));

    JSGlobalObject* globalObject = exec->callee()->globalObject();

    JSPromise* promise = JSPromise::createWithResolver(exec->vm(), globalObject);
    promise->resolver()->resolve(exec, exec->uncheckedArgument(0));

    return JSValue::encode(promise);
}
EncodedJSValue JSC_HOST_CALL constructJSReadableStreamReader(ExecState* state)
{
    JSReadableStream* stream = jsDynamicCast<JSReadableStream*>(state->argument(0));
    if (!stream)
        return throwVMError(state, createTypeError(state, ASCIILiteral("ReadableStreamReader constructor parameter is not a ReadableStream")));

    JSValue jsFunction = stream->get(state, Identifier::fromString(state, "getReader"));

    CallData callData;
    CallType callType = getCallData(jsFunction, callData);
    MarkedArgumentBuffer noArguments;
    return JSValue::encode(call(state, jsFunction, callType, callData, stream, noArguments));
}
예제 #3
0
EncodedJSValue JSC_HOST_CALL makeGetterTypeErrorForBuiltins(ExecState* execState)
{
    ASSERT(execState);
    ASSERT(execState->argumentCount() == 2);
    VM& vm = execState->vm();
    auto scope = DECLARE_CATCH_SCOPE(vm);

    auto interfaceName = execState->uncheckedArgument(0).getString(execState);
    ASSERT_UNUSED(scope, !scope.exception());
    auto attributeName = execState->uncheckedArgument(1).getString(execState);
    ASSERT(!scope.exception());
    return JSValue::encode(createTypeError(execState, makeGetterTypeErrorMessage(interfaceName.utf8().data(), attributeName.utf8().data())));
}
void JSPannerNode::setPanningModel(ExecState* exec, JSValue value)
{
    PannerNode& imp = impl();

#if ENABLE(LEGACY_WEB_AUDIO)
    if (value.isNumber()) {
        uint32_t model = value.toUInt32(exec);
        if (!imp.setPanningModel(model))
            exec->vm().throwException(exec, createTypeError(exec, "Illegal panningModel"));
        return;
    }
#endif

    if (value.isString()) {
        String model = value.toString(exec)->value(exec);
        if (model == "equalpower" || model == "HRTF" || model == "soundfield") {
            imp.setPanningModel(model);
            return;
        }
    }
    
    exec->vm().throwException(exec, createTypeError(exec, "Illegal panningModel"));
}
void JSPannerNode::setDistanceModel(ExecState* exec, JSValue value)
{
    PannerNode& imp = impl();

#if ENABLE(LEGACY_WEB_AUDIO)
    if (value.isNumber()) {
        uint32_t model = value.toUInt32(exec);
        if (!imp.setDistanceModel(model))
            exec->vm().throwException(exec, createTypeError(exec, "Illegal distanceModel"));
        return;
    }
#endif

    if (value.isString()) {
        String model = value.toString(exec)->value(exec);
        if (model == "linear" || model == "inverse" || model == "exponential") {
            imp.setDistanceModel(model);
            return;
        }
    }
    
    exec->vm().throwException(exec, createTypeError(exec, "Illegal distanceModel"));
}
예제 #6
0
EncodedJSValue JSC_HOST_CALL dateProtoFuncToJSON(ExecState* exec)
{
    JSValue thisValue = exec->thisValue();
    JSObject* object = jsCast<JSObject*>(thisValue.toThis(exec, NotStrictMode));
    if (exec->hadException())
        return JSValue::encode(jsNull());
    
    JSValue toISOValue = object->get(exec, exec->vm().propertyNames->toISOString);
    if (exec->hadException())
        return JSValue::encode(jsNull());

    CallData callData;
    CallType callType = getCallData(toISOValue, callData);
    if (callType == CallTypeNone)
        return throwVMError(exec, createTypeError(exec, ASCIILiteral("toISOString is not a function")));

    JSValue result = call(exec, asObject(toISOValue), callType, callData, object, exec->emptyList());
    if (exec->hadException())
        return JSValue::encode(jsNull());
    if (result.isObject())
        return throwVMError(exec, createTypeError(exec, ASCIILiteral("toISOString did not return a primitive value")));
    return JSValue::encode(result);
}
void JSOscillatorNode::setType(ExecState* exec, JSValue value)
{
    OscillatorNode& imp = impl();

#if ENABLE(LEGACY_WEB_AUDIO)
    if (value.isNumber()) {
        uint32_t type = value.toUInt32(exec);
        if (!imp.setType(type))
            exec->vm().throwException(exec, createTypeError(exec, "Illegal OscillatorNode type"));
        return;
    }
#endif

    if (value.isString()) {
        String type = value.toString(exec)->value(exec);
        if (type == "sine" || type == "square" || type == "sawtooth" || type == "triangle") {
            imp.setType(type);
            return;
        }
    }
    
    exec->vm().throwException(exec, createTypeError(exec, "Illegal OscillatorNode type"));
}
static EncodedJSValue JSC_HOST_CALL constructPromise(ExecState* exec)
{
    if (!exec->argumentCount())
        return throwVMError(exec, createTypeError(exec, "Expected at least one argument"));

    JSValue function = exec->argument(0);

    CallData callData;
    CallType callType = getCallData(function, callData);
    if (callType == CallTypeNone)
        return throwVMError(exec, createTypeError(exec, "Expected function as as first argument"));

    JSGlobalObject* globalObject = asInternalFunction(exec->callee())->globalObject();
    
    // 1. Let promise be a new promise.
    JSPromise* promise = JSPromise::createWithResolver(exec->vm(), globalObject);

    // 2. Let resolver be promise's associated resolver.
    JSPromiseResolver* resolver = promise->resolver();

    // 3. Set init's callback this value to promise.
    // 4. Invoke init with resolver passed as parameter.
    MarkedArgumentBuffer initArguments;
    initArguments.append(resolver);
    call(exec, function, callType, callData, promise, initArguments);

    // 5. If init threw an exception, catch it, and then, if resolver's resolved flag
    //    is unset, run resolver's reject with the thrown exception as argument.
    if (exec->hadException()) {
        JSValue exception = exec->exception();
        exec->clearException();

        resolver->rejectIfNotResolved(exec, exception);
    }

    return JSValue::encode(promise);
}
EncodedJSValue JSC_HOST_CALL JSPromisePrototypeFuncCatch(ExecState* exec)
{
    JSPromise* thisObject = jsDynamicCast<JSPromise*>(exec->thisValue());
    if (!thisObject)
        return throwVMError(exec, createTypeError(exec, "Receiver of catch must be a Promise"));
    
    JSValue rejectCallback = exec->argument(0);
    if (!rejectCallback.isUndefined()) {
        CallData callData;
        CallType callType = getCallData(rejectCallback, callData);
        if (callType == CallTypeNone)
            return throwVMError(exec, createTypeError(exec, "Expected function or undefined as as first argument"));
    }

    JSFunction* callee = jsCast<JSFunction*>(exec->callee());
    JSGlobalObject* globalObject = callee->globalObject();

    // 1. Let promise be a new promise.
    JSPromise* promise = JSPromise::createWithResolver(exec->vm(), globalObject);

    // 2. Let resolver be promise's associated resolver.
    JSPromiseResolver* resolver = promise->resolver();

    // 3. Let fulfillCallback be a new promise callback for resolver and its fulfill algorithm.
    InternalFunction* fulfillWrapper = JSPromiseCallback::create(exec, globalObject, globalObject->promiseCallbackStructure(), resolver, JSPromiseCallback::Fulfill);

    // 4. Let rejectWrapper be a promise wrapper callback for resolver and rejectCallback if rejectCallback is
    //    not omitted and a promise callback for resolver and its reject algorithm otherwise.
    InternalFunction* rejectWrapper = wrapCallback(exec, globalObject, rejectCallback, resolver, JSPromiseCallback::Reject);

    // 5. Append fulfillWrapper and rejectWrapper to the context object.
    thisObject->appendCallbacks(exec, fulfillWrapper, rejectWrapper);

    // 6. Return promise.
    return JSValue::encode(promise);
}
EncodedJSValue setData(ExecState* exec)
{
    JSDataView* dataView = jsDynamicCast<JSDataView*>(exec->thisValue());
    if (!dataView)
        return throwVMError(exec, createTypeError(exec, "Receiver of DataView method must be a DataView"));
    
    if (exec->argumentCount() < 2)
        return throwVMError(exec, createTypeError(exec, "Need at least two argument (the byteOffset and value)"));
    
    unsigned byteOffset = exec->uncheckedArgument(0).toUInt32(exec);
    if (exec->hadException())
        return JSValue::encode(jsUndefined());
    
    typename Adaptor::Type value = toNativeFromValue<Adaptor>(exec, exec->uncheckedArgument(1));
    if (exec->hadException())
        return JSValue::encode(jsUndefined());
    
    bool littleEndian = false;
    unsigned elementSize = sizeof(typename Adaptor::Type);
    if (elementSize > 1 && exec->argumentCount() >= 3) {
        littleEndian = exec->uncheckedArgument(2).toBoolean(exec);
        if (exec->hadException())
            return JSValue::encode(jsUndefined());
    }
    
    unsigned byteLength = dataView->length();
    if (elementSize > byteLength || byteOffset > byteLength - elementSize)
        return throwVMError(exec, createRangeError(exec, "Out of bounds access"));
    
    if (needToFlipBytesIfLittleEndian(littleEndian))
        value = flipBytes(value);
    
    *reinterpret_cast<typename Adaptor::Type*>(static_cast<uint8_t*>(dataView->vector()) + byteOffset) = value;
    
    return JSValue::encode(jsUndefined());
}
예제 #11
0
EncodedJSValue JSC_HOST_CALL jsTestOverridingNameGetterPrototypeFunctionAnotherFunction(ExecState* exec)
{
    JSValue thisValue = exec->hostThisValue();
    if (!thisValue.inherits(&JSTestOverridingNameGetter::s_info))
        return throwVMTypeError(exec);
    JSTestOverridingNameGetter* castedThis = static_cast<JSTestOverridingNameGetter*>(asObject(thisValue));
    ASSERT_GC_OBJECT_INHERITS(castedThis, &JSTestOverridingNameGetter::s_info);
    TestOverridingNameGetter* impl = static_cast<TestOverridingNameGetter*>(castedThis->impl());
    if (exec->argumentCount() < 1)
        return throwVMError(exec, createTypeError(exec, "Not enough arguments"));
    const String& str(ustringToString(MAYBE_MISSING_PARAMETER(exec, 0, MissingIsUndefined).isEmpty() ? UString() : MAYBE_MISSING_PARAMETER(exec, 0, MissingIsUndefined).toString(exec)->value(exec)));
    if (exec->hadException())
        return JSValue::encode(jsUndefined());
    impl->anotherFunction(str);
    return JSValue::encode(jsUndefined());
}
EncodedJSValue JSC_HOST_CALL objectConstructorDefineProperty(ExecState* exec)
{
    if (!exec->argument(0).isObject())
        return throwVMError(exec, createTypeError(exec, ASCIILiteral("Properties can only be defined on Objects.")));
    JSObject* O = asObject(exec->argument(0));
    String propertyName = exec->argument(1).toString(exec)->value(exec);
    if (exec->hadException())
        return JSValue::encode(jsNull());
    PropertyDescriptor descriptor;
    if (!toPropertyDescriptor(exec, exec->argument(2), descriptor))
        return JSValue::encode(jsNull());
    ASSERT((descriptor.attributes() & Accessor) || (!descriptor.isAccessorDescriptor()));
    ASSERT(!exec->hadException());
    O->methodTable()->defineOwnProperty(O, exec, Identifier(exec, propertyName), descriptor, true);
    return JSValue::encode(O);
}
예제 #13
0
EncodedJSValue JSC_HOST_CALL jsMessagePortPrototypeFunctionRemoveEventListener(ExecState* exec)
{
    JSValue thisValue = exec->hostThisValue();
    if (!thisValue.inherits(&JSMessagePort::s_info))
        return throwVMTypeError(exec);
    JSMessagePort* castedThis = static_cast<JSMessagePort*>(asObject(thisValue));
    ASSERT_GC_OBJECT_INHERITS(castedThis, &JSMessagePort::s_info);
    MessagePort* imp = static_cast<MessagePort*>(castedThis->impl());
    if (exec->argumentCount() < 2)
        return throwVMError(exec, createTypeError(exec, "Not enough arguments"));
    JSValue listener = exec->argument(1);
    if (!listener.isObject())
        return JSValue::encode(jsUndefined());
    imp->removeEventListener(ustringToAtomicString(exec->argument(0).toString(exec)), JSEventListener::create(asObject(listener), castedThis, false, currentWorld(exec)).get(), exec->argument(2).toBoolean(exec));
    return JSValue::encode(jsUndefined());
}
예제 #14
0
JSValue JSSVGMatrix::multiply(ExecState* exec)
{
    if (exec->argumentCount() < 1)
        return throwError(exec, createSyntaxError(exec, "Not enough arguments"));

    if (!exec->argument(0).inherits(&JSSVGMatrix::s_info))
        return throwError(exec, createTypeError(exec, "secondMatrix argument was not a SVGMatrix"));

    JSSVGMatrix* matrixObj = static_cast<JSSVGMatrix*>(asObject(exec->argument(0)));

    AffineTransform m1(*impl());
    AffineTransform m2(*(matrixObj->impl()));

    SVGElement* context = JSSVGContextCache::svgContextForDOMObject(this);
    return toJS(exec, globalObject(), JSSVGStaticPODTypeWrapper<AffineTransform>::create(m1.multLeft(m2)).get(), context);
}
예제 #15
0
EncodedJSValue JSC_HOST_CALL jsHTMLKeygenElementPrototypeFunctionSetCustomValidity(ExecState* exec)
{
    JSValue thisValue = exec->hostThisValue();
    if (!thisValue.inherits(&JSHTMLKeygenElement::s_info))
        return throwVMTypeError(exec);
    JSHTMLKeygenElement* castedThis = static_cast<JSHTMLKeygenElement*>(asObject(thisValue));
    ASSERT_GC_OBJECT_INHERITS(castedThis, &JSHTMLKeygenElement::s_info);
    HTMLKeygenElement* imp = static_cast<HTMLKeygenElement*>(castedThis->impl());
    if (exec->argumentCount() < 1)
        return throwVMError(exec, createTypeError(exec, "Not enough arguments"));
    const String& error(valueToStringWithUndefinedOrNullCheck(exec, exec->argument(0)));
    if (exec->hadException())
        return JSValue::encode(jsUndefined());

    imp->setCustomValidity(error);
    return JSValue::encode(jsUndefined());
}
예제 #16
0
JSObject* createNotAConstructorError(ExecState* exec, JSValue value, unsigned bytecodeOffset, CodeBlock* codeBlock)
{
    int startOffset = 0;
    int endOffset = 0;
    int divotPoint = 0;
    int line = codeBlock->expressionRangeForBytecodeOffset(exec, bytecodeOffset, divotPoint, startOffset, endOffset);

    // We're in a "new" expression, so we need to skip over the "new.." part
    int startPoint = divotPoint - (startOffset ? startOffset - 4 : 0); // -4 for "new "
    const UChar* data = codeBlock->source()->data();
    while (startPoint < divotPoint && isStrWhiteSpace(data[startPoint]))
        startPoint++;
    
    UString errorMessage = createErrorMessage(exec, codeBlock, line, startPoint, divotPoint, value, "not a constructor");
    JSObject* exception = addErrorInfo(exec, createTypeError(exec, errorMessage), line, codeBlock->ownerExecutable()->source(), divotPoint, startOffset, endOffset);
    return exception;
}
예제 #17
0
EncodedJSValue JSC_HOST_CALL constructJSMutationObserver(ExecState* exec)
{
    if (exec->argumentCount() < 1)
        return throwVMError(exec, createNotEnoughArgumentsError(exec));

    JSObject* object = exec->argument(0).getObject();
    CallData callData;
    if (!object || object->methodTable()->getCallData(object, callData) == CallType::None)
        return throwVMError(exec, createTypeError(exec, "Callback argument must be a function"));

    DOMConstructorObject* jsConstructor = jsCast<DOMConstructorObject*>(exec->callee());
    auto callback = JSMutationCallback::create(object, jsConstructor->globalObject());
    JSObject* jsObserver = asObject(toJS(exec, jsConstructor->globalObject(), MutationObserver::create(WTFMove(callback))));
    PrivateName propertyName;
    jsObserver->putDirect(jsConstructor->globalObject()->vm(), propertyName, object);
    return JSValue::encode(jsObserver);
}
예제 #18
0
bool JSObject::hasInstance(ExecState* exec, JSValue value, JSValue proto)
{
    if (!value.isObject())
        return false;

    if (!proto.isObject()) {
        throwError(exec, createTypeError(exec, "instanceof called on an object with an invalid prototype property."));
        return false;
    }

    JSObject* object = asObject(value);
    while ((object = object->prototype().getObject())) {
        if (proto == object)
            return true;
    }
    return false;
}
예제 #19
0
EncodedJSValue JSC_HOST_CALL jsFloat64ArrayPrototypeFunctionFoo(ExecState* exec)
{
    JSValue thisValue = exec->hostThisValue();
    if (!thisValue.inherits(&JSFloat64Array::s_info))
        return throwVMTypeError(exec);
    JSFloat64Array* castedThis = static_cast<JSFloat64Array*>(asObject(thisValue));
    ASSERT_GC_OBJECT_INHERITS(castedThis, &JSFloat64Array::s_info);
    Float64Array* impl = static_cast<Float64Array*>(castedThis->impl());
    if (exec->argumentCount() < 1)
        return throwVMError(exec, createTypeError(exec, "Not enough arguments"));
    Float32Array* array(toFloat32Array(MAYBE_MISSING_PARAMETER(exec, 0, MissingIsUndefined)));
    if (exec->hadException())
        return JSValue::encode(jsUndefined());

    JSC::JSValue result = toJS(exec, castedThis->globalObject(), WTF::getPtr(impl->foo(array)));
    return JSValue::encode(result);
}
예제 #20
0
EncodedJSValue JSC_HOST_CALL jsAudioBufferSourceNodePrototypeFunctionNoteOff(ExecState* exec)
{
    JSValue thisValue = exec->hostThisValue();
    if (!thisValue.inherits(&JSAudioBufferSourceNode::s_info))
        return throwVMTypeError(exec);
    JSAudioBufferSourceNode* castedThis = static_cast<JSAudioBufferSourceNode*>(asObject(thisValue));
    ASSERT_GC_OBJECT_INHERITS(castedThis, &JSAudioBufferSourceNode::s_info);
    AudioBufferSourceNode* imp = static_cast<AudioBufferSourceNode*>(castedThis->impl());
    if (exec->argumentCount() < 1)
        return throwVMError(exec, createTypeError(exec, "Not enough arguments"));
    float when(exec->argument(0).toFloat(exec));
    if (exec->hadException())
        return JSValue::encode(jsUndefined());

    imp->noteOff(when);
    return JSValue::encode(jsUndefined());
}
예제 #21
0
bool JSFunction::defineOwnProperty(JSObject* object, ExecState* exec, const Identifier& propertyName, PropertyDescriptor& descriptor, bool throwException)
{
    JSFunction* thisObject = jsCast<JSFunction*>(object);
    if (thisObject->isHostFunction())
        return Base::defineOwnProperty(object, exec, propertyName, descriptor, throwException);

    if (propertyName == exec->propertyNames().prototype) {
        // Make sure prototype has been reified, such that it can only be overwritten
        // following the rules set out in ECMA-262 8.12.9.
        PropertySlot slot;
        thisObject->methodTable()->getOwnPropertySlot(thisObject, exec, propertyName, slot);
    } else if (propertyName == exec->propertyNames().arguments || propertyName == exec->propertyNames().length || propertyName == exec->propertyNames().caller) {
        if (!object->isExtensible()) {
            if (throwException)
                throwError(exec, createTypeError(exec, "Attempting to define property on object that is not extensible."));
            return false;
        }
        if (descriptor.configurablePresent() && descriptor.configurable()) {
            if (throwException)
                throwError(exec, createTypeError(exec, "Attempting to configurable attribute of unconfigurable property."));
            return false;
        }
        if (descriptor.enumerablePresent() && descriptor.enumerable()) {
            if (throwException)
                throwError(exec, createTypeError(exec, "Attempting to change enumerable attribute of unconfigurable property."));
            return false;
        }
        if (descriptor.isAccessorDescriptor()) {
            if (throwException)
                throwError(exec, createTypeError(exec, "Attempting to change access mechanism for an unconfigurable property."));
            return false;
        }
        if (descriptor.writablePresent() && descriptor.writable()) {
            if (throwException)
                throwError(exec, createTypeError(exec, "Attempting to change writable attribute of unconfigurable property."));
            return false;
        }
        if (!descriptor.value())
            return true;
        if (propertyName == exec->propertyNames().arguments && sameValue(exec, descriptor.value(), exec->interpreter()->retrieveArgumentsFromVMCode(exec, thisObject)))
            return true;
        if (propertyName == exec->propertyNames().length && sameValue(exec, descriptor.value(), jsNumber(thisObject->jsExecutable()->parameterCount())))
            return true;
        if (propertyName == exec->propertyNames().caller && sameValue(exec, descriptor.value(), exec->interpreter()->retrieveCallerFromVMCode(exec, thisObject)))
            return true;
        if (throwException)
            throwError(exec, createTypeError(exec, "Attempting to change value of a readonly property."));
        return false;
    }

    return Base::defineOwnProperty(object, exec, propertyName, descriptor, throwException);
}
예제 #22
0
EncodedJSValue JSC_HOST_CALL jsTouchListPrototypeFunctionItem(ExecState* exec)
{
    JSValue thisValue = exec->hostThisValue();
    if (!thisValue.inherits(&JSTouchList::s_info))
        return throwVMTypeError(exec);
    JSTouchList* castedThis = static_cast<JSTouchList*>(asObject(thisValue));
    ASSERT_GC_OBJECT_INHERITS(castedThis, &JSTouchList::s_info);
    TouchList* imp = static_cast<TouchList*>(castedThis->impl());
    if (exec->argumentCount() < 1)
        return throwVMError(exec, createTypeError(exec, "Not enough arguments"));
    unsigned index(exec->argument(0).toUInt32(exec));
    if (exec->hadException())
        return JSValue::encode(jsUndefined());


    JSC::JSValue result = toJS(exec, castedThis->globalObject(), WTF::getPtr(imp->item(index)));
    return JSValue::encode(result);
}
예제 #23
0
KJS::Object KstBindImage::construct(KJS::ExecState *exec, const KJS::List& args) {
  KstMatrixPtr matrix;

  if (args.size() > 0) {
    matrix = extractMatrix(exec, args[0]);
    if (!matrix) {
      return createTypeError(exec, 0);
    }
  }

  KstImagePtr image = new KstImage(QString::null, matrix, 10, QColor(0,0,0), 1);

  KST::dataObjectList.lock().writeLock();
  KST::dataObjectList.append(image.data());
  KST::dataObjectList.lock().unlock();

  return KJS::Object(new KstBindImage(exec, image));
}
예제 #24
0
EncodedJSValue JSC_HOST_CALL objectProtoFuncDefineSetter(ExecState* exec)
{
    JSObject* thisObject = exec->thisValue().toThis(exec, StrictMode).toObject(exec);
    if (exec->hadException())
        return JSValue::encode(jsUndefined());

    JSValue set = exec->argument(1);
    CallData callData;
    if (getCallData(set, callData) == CallTypeNone)
        return throwVMError(exec, createTypeError(exec, ASCIILiteral("invalid setter usage")));

    PropertyDescriptor descriptor;
    descriptor.setSetter(set);
    descriptor.setEnumerable(true);
    descriptor.setConfigurable(true);
    thisObject->methodTable(exec->vm())->defineOwnProperty(thisObject, exec, exec->argument(0).toString(exec)->toIdentifier(exec), descriptor, false);

    return JSValue::encode(jsUndefined());
}
예제 #25
0
EncodedJSValue JSC_HOST_CALL jsTestEventTargetPrototypeFunctionDispatchEvent(ExecState* exec)
{
    JSValue thisValue = exec->hostThisValue();
    if (!thisValue.inherits(&JSTestEventTarget::s_info))
        return throwVMTypeError(exec);
    JSTestEventTarget* castedThis = static_cast<JSTestEventTarget*>(asObject(thisValue));
    ASSERT_GC_OBJECT_INHERITS(castedThis, &JSTestEventTarget::s_info);
    TestEventTarget* impl = static_cast<TestEventTarget*>(castedThis->impl());
    if (exec->argumentCount() < 1)
        return throwVMError(exec, createTypeError(exec, "Not enough arguments"));
    ExceptionCode ec = 0;
    Event* evt(toEvent(MAYBE_MISSING_PARAMETER(exec, 0, DefaultIsUndefined)));
    if (exec->hadException())
        return JSValue::encode(jsUndefined());

    JSC::JSValue result = jsBoolean(impl->dispatchEvent(evt, ec));
    setDOMException(exec, ec);
    return JSValue::encode(result);
}
예제 #26
0
EncodedJSValue JSC_HOST_CALL jsDOMApplicationCachePrototypeFunctionDispatchEvent(ExecState* exec)
{
    JSValue thisValue = exec->hostThisValue();
    if (!thisValue.inherits(&JSDOMApplicationCache::s_info))
        return throwVMTypeError(exec);
    JSDOMApplicationCache* castedThis = static_cast<JSDOMApplicationCache*>(asObject(thisValue));
    ASSERT_GC_OBJECT_INHERITS(castedThis, &JSDOMApplicationCache::s_info);
    DOMApplicationCache* imp = static_cast<DOMApplicationCache*>(castedThis->impl());
    if (exec->argumentCount() < 1)
        return throwVMError(exec, createTypeError(exec, "Not enough arguments"));
    ExceptionCode ec = 0;
    Event* evt(toEvent(exec->argument(0)));
    if (exec->hadException())
        return JSValue::encode(jsUndefined());


    JSC::JSValue result = jsBoolean(imp->dispatchEvent(evt, ec));
    setDOMException(exec, ec);
    return JSValue::encode(result);
}
예제 #27
0
KJS::Value KstBindImage::smartThreshold(KJS::ExecState *exec, const KJS::List& args) {
  KstImagePtr d = makeImage(_d);
  if (!d) {
    return createInternalError(exec);
  }

  if (args.size() != 1) {
    return createSyntaxError(exec);
  }

  if (args[0].type() != KJS::NumberType) {
    return createTypeError(exec, 0);
  }

  double per = args[0].toNumber(exec);
  KstReadLocker rl(d);

  d->setThresholdToSpikeInsensitive(per);
  return KJS::Undefined();
}
예제 #28
0
KJS::Object KstBindLine::construct(KJS::ExecState *exec, const KJS::List& args) {
  if (args.size() != 1) {
    return createSyntaxError(exec);
  }

  KstViewObjectPtr view = extractViewObject(exec, args[0]);
  if (!view) {
    KstViewWindow *w = extractWindow(exec, args[0]);
    if (w) {
      view = w->view();
    } else {
      return createTypeError(exec, 0);
    }
  }

  KstViewLinePtr b = new KstViewLine;
  view->appendChild(b.data());
  KstApp::inst()->paintAll(KstPainter::P_PAINT);
  return KJS::Object(new KstBindLine(exec, b));
}
예제 #29
0
JSPromise* ReadableJSStream::invoke(ExecState& state, const char* propertyName, JSValue parameter)
{
    JSValue function = getPropertyFromObject(state, *m_source.get(), propertyName);
    if (state.hadException())
        return nullptr;

    if (!function.isFunction()) {
        if (!function.isUndefined())
            throwVMError(&state, createTypeError(&state, ASCIILiteral("ReadableStream trying to call a property that is not callable")));
        return nullptr;
    }

    MarkedArgumentBuffer arguments;
    arguments.append(parameter);

    JSPromise* promise = jsDynamicCast<JSPromise*>(callFunction(state, function, m_source.get(), arguments));

    ASSERT(!(promise && state.hadException()));
    return promise;
}
예제 #30
0
KJS::Value KstBindLegend::removeCurve(KJS::ExecState *exec, const KJS::List& args) {
  if (args.size() != 1) {
    return createSyntaxError(exec);
  }

  KstBaseCurvePtr curve;
  curve = extractVCurve(exec, args[0], false);
  if (curve) {
    KstViewLegendPtr d = makeLegend(_d);
    if (d) {
      KstWriteLocker wl(d);
      d->removeCurve(curve);
      KstApp::inst()->paintAll(KstPainter::P_PAINT);
    }
  } else {
    return createTypeError(exec, 0);
  }

  return KJS::Undefined();
}