示例#1
0
void V8Crypto::getRandomValuesMethodCustom(const v8::FunctionCallbackInfo<v8::Value>& info)
{
    ExceptionState exceptionState(ExceptionState::ExecutionContext, "getRandomValues", "Crypto", info.Holder(), info.GetIsolate());
    if (info.Length() < 1) {
        exceptionState.throwTypeError(ExceptionMessages::notEnoughArguments(1, info.Length()));
        exceptionState.throwIfNeeded();
        return;
    }

    v8::Handle<v8::Value> buffer = info[0];
    if (!V8ArrayBufferView::hasInstance(buffer, info.GetIsolate())) {
        exceptionState.throwTypeError("First argument is not an ArrayBufferView");
    } else {
        ArrayBufferView* arrayBufferView = V8ArrayBufferView::toNative(v8::Handle<v8::Object>::Cast(buffer));
        ASSERT(arrayBufferView);

        Crypto* crypto = V8Crypto::toNative(info.Holder());
        crypto->getRandomValues(arrayBufferView, exceptionState);
    }

    if (exceptionState.throwIfNeeded())
        return;

    v8SetReturnValue(info, buffer);
}
示例#2
0
EncodedJSValue JSC_HOST_CALL jsCryptoPrototypeFunctionGetRandomValues(ExecState* exec)
{
    JSValue thisValue = exec->hostThisValue();
    if (!thisValue.inherits(&JSCrypto::s_info))
        return throwVMTypeError(exec);
    JSCrypto* castedThis = static_cast<JSCrypto*>(asObject(thisValue));
    Crypto* imp = static_cast<Crypto*>(castedThis->impl());
    ExceptionCode ec = 0;
    ArrayBufferView* array(toArrayBufferView(exec->argument(0)));
    if (exec->hadException())
        return JSValue::encode(jsUndefined());

    imp->getRandomValues(array, ec);
    setDOMException(exec, ec);
    return JSValue::encode(jsUndefined());
}