v8::Handle<v8::Value> V8DataView::setUint8Callback(const v8::Arguments& args) { if (args.Length() < 2) return throwNotEnoughArgumentsError(args.GetIsolate()); DataView* imp = V8DataView::toNative(args.Holder()); ExceptionCode ec = 0; V8TRYCATCH(unsigned, byteOffset, toUInt32(args[0])); V8TRYCATCH(int, value, toInt32(args[1])); imp->setUint8(byteOffset, static_cast<uint8_t>(value), ec); if (UNLIKELY(ec)) return setDOMException(ec, args.GetIsolate()); return v8Undefined(); }
Var DataView::EntryGetterByteOffset(RecyclableObject* function, CallInfo callInfo, ...) { PROBE_STACK(function->GetScriptContext(), Js::Constants::MinStackDefault); ARGUMENTS(args, callInfo); ScriptContext* scriptContext = function->GetScriptContext(); Assert(!(callInfo.Flags & CallFlags_New)); if (args.Info.Count == 0 || !DataView::Is(args[0])) { JavascriptError::ThrowTypeError(scriptContext, JSERR_This_NeedDataView); } DataView* dataView = DataView::FromVar(args[0]); ArrayBuffer* arrayBuffer = dataView->GetArrayBuffer(); if (arrayBuffer == nullptr) { JavascriptError::ThrowTypeError(scriptContext, JSERR_NeedArrayBufferObject); } else if (arrayBuffer->IsDetached()) { return TaggedInt::ToVarUnchecked(0); } return JavascriptNumber::ToVar(dataView->GetByteOffset(), scriptContext); }
static v8::Handle<v8::Value> getInt32Callback(const v8::Arguments& args) { INC_STATS("DOM.DataView.getInt32"); if (args.Length() < 1) return throwError("Not enough arguments", V8Proxy::TypeError); DataView* imp = V8DataView::toNative(args.Holder()); ExceptionCode ec = 0; { EXCEPTION_BLOCK(unsigned, byteOffset, toUInt32(MAYBE_MISSING_PARAMETER(args, 0, MissingIsUndefined))); if (args.Length() <= 1) { int result = imp->getInt32(byteOffset, ec); if (UNLIKELY(ec)) goto fail; return v8::Integer::New(result); } EXCEPTION_BLOCK(bool, littleEndian, MAYBE_MISSING_PARAMETER(args, 1, MissingIsUndefined)->BooleanValue()); int result = imp->getInt32(byteOffset, littleEndian, ec); if (UNLIKELY(ec)) goto fail; return v8::Integer::New(result); } fail: V8Proxy::setDOMException(ec); return v8::Handle<v8::Value>(); }
static v8::Handle<v8::Value> setFloat64Callback(const v8::Arguments& args) { INC_STATS("DOM.DataView.setFloat64"); if (args.Length() < 2) return throwError("Not enough arguments", V8Proxy::TypeError); DataView* imp = V8DataView::toNative(args.Holder()); ExceptionCode ec = 0; { EXCEPTION_BLOCK(unsigned, byteOffset, toUInt32(MAYBE_MISSING_PARAMETER(args, 0, MissingIsUndefined))); EXCEPTION_BLOCK(double, value, static_cast<double>(MAYBE_MISSING_PARAMETER(args, 1, MissingIsUndefined)->NumberValue())); if (args.Length() <= 2) { imp->setFloat64(byteOffset, value, ec); if (UNLIKELY(ec)) goto fail; return v8::Handle<v8::Value>(); } EXCEPTION_BLOCK(bool, littleEndian, MAYBE_MISSING_PARAMETER(args, 2, MissingIsUndefined)->BooleanValue()); imp->setFloat64(byteOffset, value, littleEndian, ec); if (UNLIKELY(ec)) goto fail; return v8::Handle<v8::Value>(); } fail: V8Proxy::setDOMException(ec); return v8::Handle<v8::Value>(); }
EncodedJSValue JSC_HOST_CALL jsDataViewPrototypeFunctionSetFloat64(ExecState* exec) { JSValue thisValue = exec->hostThisValue(); if (!thisValue.inherits(&JSDataView::s_info)) return throwVMTypeError(exec); JSDataView* castedThis = static_cast<JSDataView*>(asObject(thisValue)); ASSERT_GC_OBJECT_INHERITS(castedThis, &JSDataView::s_info); DataView* imp = static_cast<DataView*>(castedThis->impl()); if (exec->argumentCount() < 2) return throwVMError(exec, createSyntaxError(exec, "Not enough arguments")); ExceptionCode ec = 0; unsigned byteOffset(exec->argument(0).toUInt32(exec)); if (exec->hadException()) return JSValue::encode(jsUndefined()); double value(exec->argument(1).toNumber(exec)); if (exec->hadException()) return JSValue::encode(jsUndefined()); int argsCount = exec->argumentCount(); if (argsCount <= 2) { imp->setFloat64(byteOffset, value, ec); setDOMException(exec, ec); return JSValue::encode(jsUndefined()); } bool littleEndian(exec->argument(2).toBoolean(exec)); if (exec->hadException()) return JSValue::encode(jsUndefined()); imp->setFloat64(byteOffset, value, littleEndian, ec); setDOMException(exec, ec); return JSValue::encode(jsUndefined()); }
v8::Handle<v8::Value> V8DataView::getUint8Callback(const v8::Arguments& args) { if (args.Length() < 1) return throwNotEnoughArgumentsError(args.GetIsolate()); DataView* imp = V8DataView::toNative(args.Holder()); ExceptionCode ec = 0; V8TRYCATCH(unsigned, byteOffset, toUInt32(args[0])); uint8_t result = imp->getUint8(byteOffset, ec); if (UNLIKELY(ec)) return setDOMException(ec, args.GetIsolate()); return v8Integer(result, args.GetIsolate()); }
v8::Handle<v8::Value> V8DataView::setInt8Callback(const v8::Arguments& args) { INC_STATS("DOM.DataView.setInt8"); if (args.Length() < 2) return throwError("Not enough arguments", V8Proxy::SyntaxError); DataView* imp = V8DataView::toNative(args.Holder()); ExceptionCode ec = 0; EXCEPTION_BLOCK(unsigned, byteOffset, toUInt32(args[0])); EXCEPTION_BLOCK(int, value, toInt32(args[1])); imp->setInt8(byteOffset, static_cast<int8_t>(value), ec); if (UNLIKELY(ec)) V8Proxy::setDOMException(ec); return v8::Handle<v8::Value>(); }
v8::Handle<v8::Value> V8DataView::getUint8Callback(const v8::Arguments& args) { INC_STATS("DOM.DataView.getUint8"); if (args.Length() < 1) return throwError("Not enough arguments", V8Proxy::SyntaxError); DataView* imp = V8DataView::toNative(args.Holder()); ExceptionCode ec = 0; EXCEPTION_BLOCK(unsigned, byteOffset, toUInt32(args[0])); uint8_t result = imp->getUint8(byteOffset, ec); if (UNLIKELY(ec)) { V8Proxy::setDOMException(ec); return v8::Handle<v8::Value>(); } return v8::Integer::New(result); }
void BaseTestDataAccess::testDataView() { NDSize zcount = {2, 5, 2}; NDSize zoffset = {0, 5, 2}; DataView io = DataView(data_array, zcount, zoffset); CPPUNIT_ASSERT_EQUAL(zcount, io.dataExtent()); CPPUNIT_ASSERT_EQUAL(data_array.dataType(), io.dataType()); typedef boost::multi_array<double, 3> array_type; array_type data(boost::extents[2][5][2]); io.getData(data); const array_type::size_type *ext = data.shape(); for (size_t i = 0; i < 3; i++) { CPPUNIT_ASSERT_EQUAL(static_cast<array_type::size_type >(zcount[i]), ext[i]); } array_type ref; data_array.getData(ref); for(size_t i = 0; i < zcount[0]; ++i) { for(size_t j = 0; j < zcount[1]; ++j) { for(size_t k = 0; k < zcount[2]; ++k) { CPPUNIT_ASSERT_DOUBLES_EQUAL(ref[i + 0][j + 5][k + 2], data[i][j][k], std::numeric_limits<double>::epsilon()); data[i][j][k] = 0.0; } } } io.setData(data, {0, 0, 0}); data_array.getData(ref); for(size_t i = 0; i < zcount[0]; ++i) { for(size_t j = 0; j < zcount[1]; ++j) { for(size_t k = 0; k < zcount[2]; ++k) { CPPUNIT_ASSERT_DOUBLES_EQUAL(ref[i + 0][j + 5][k + 2], 0.0, std::numeric_limits<double>::epsilon()); } } } double val = 0.0; CPPUNIT_ASSERT_THROW(io.getData(val, {}, {0, 0, 3}), OutOfBounds); array_type r2d2(boost::extents[3][3][3]); CPPUNIT_ASSERT_THROW(io.getData(r2d2, {3, 3, 3}, {}), OutOfBounds); CPPUNIT_ASSERT_THROW(io.dataExtent(zcount), std::runtime_error); }