summaryrefslogtreecommitdiff
path: root/Source/JavaScriptCore/runtime/JSDataView.cpp
diff options
context:
space:
mode:
authorLorry Tar Creator <lorry-tar-importer@lorry>2016-05-24 08:28:08 +0000
committerLorry Tar Creator <lorry-tar-importer@lorry>2016-05-24 08:28:08 +0000
commita4e969f4965059196ca948db781e52f7cfebf19e (patch)
tree6ca352808c8fdc52006a0f33f6ae3c593b23867d /Source/JavaScriptCore/runtime/JSDataView.cpp
parent41386e9cb918eed93b3f13648cbef387e371e451 (diff)
downloadWebKitGtk-tarball-a4e969f4965059196ca948db781e52f7cfebf19e.tar.gz
webkitgtk-2.12.3webkitgtk-2.12.3
Diffstat (limited to 'Source/JavaScriptCore/runtime/JSDataView.cpp')
-rw-r--r--Source/JavaScriptCore/runtime/JSDataView.cpp82
1 files changed, 73 insertions, 9 deletions
diff --git a/Source/JavaScriptCore/runtime/JSDataView.cpp b/Source/JavaScriptCore/runtime/JSDataView.cpp
index 77640cdaf..75c26dbfe 100644
--- a/Source/JavaScriptCore/runtime/JSDataView.cpp
+++ b/Source/JavaScriptCore/runtime/JSDataView.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2013 Apple Inc. All rights reserved.
+ * Copyright (C) 2013-2015 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -29,12 +29,13 @@
#include "ArrayBufferView.h"
#include "DataView.h"
#include "Error.h"
-#include "Operations.h"
+#include "JSCInlines.h"
+#include "Reject.h"
namespace JSC {
const ClassInfo JSDataView::s_info = {
- "DataView", &Base::s_info, 0, 0, CREATE_METHOD_TABLE(JSDataView)};
+ "DataView", &Base::s_info, 0, CREATE_METHOD_TABLE(JSDataView)};
JSDataView::JSDataView(VM& vm, ConstructionContext& context, ArrayBuffer* buffer)
: Base(vm, context)
@@ -47,10 +48,13 @@ JSDataView* JSDataView::create(
unsigned byteOffset, unsigned byteLength)
{
RefPtr<ArrayBuffer> buffer = passedBuffer;
- if (!ArrayBufferView::verifySubRange<uint8_t>(buffer, byteOffset, byteLength)) {
- throwVMError(
- exec, createRangeError(exec, "Byte offset and length out of range of buffer"));
- return 0;
+ if (!ArrayBufferView::verifySubRangeLength(buffer, byteOffset, byteLength, sizeof(uint8_t))) {
+ throwVMError(exec, createRangeError(exec, ASCIILiteral("Length out of range of buffer")));
+ return nullptr;
+ }
+ if (!ArrayBufferView::verifyByteOffsetAlignment(byteOffset, sizeof(uint8_t))) {
+ exec->vm().throwException(exec, createRangeError(exec, ASCIILiteral("Byte offset is not aligned")));
+ return nullptr;
}
VM& vm = exec->vm();
ConstructionContext context(
@@ -80,6 +84,12 @@ bool JSDataView::set(ExecState*, JSObject*, unsigned, unsigned)
return false;
}
+bool JSDataView::setIndex(ExecState*, unsigned, JSValue)
+{
+ UNREACHABLE_FOR_PLATFORM();
+ return false;
+}
+
PassRefPtr<DataView> JSDataView::typedImpl()
{
return DataView::create(buffer(), byteOffset(), length());
@@ -93,10 +103,64 @@ bool JSDataView::getOwnPropertySlot(
slot.setValue(thisObject, DontEnum | ReadOnly, jsNumber(thisObject->m_length));
return true;
}
-
+ if (propertyName == exec->propertyNames().byteOffset) {
+ slot.setValue(thisObject, DontEnum | ReadOnly, jsNumber(thisObject->byteOffset()));
+ return true;
+ }
+
return Base::getOwnPropertySlot(thisObject, exec, propertyName, slot);
}
+void JSDataView::put(
+ JSCell* cell, ExecState* exec, PropertyName propertyName, JSValue value,
+ PutPropertySlot& slot)
+{
+ JSDataView* thisObject = jsCast<JSDataView*>(cell);
+ if (propertyName == exec->propertyNames().byteLength
+ || propertyName == exec->propertyNames().byteOffset) {
+ reject(exec, slot.isStrictMode(), "Attempting to write to read-only typed array property.");
+ return;
+ }
+
+ Base::put(thisObject, exec, propertyName, value, slot);
+}
+
+bool JSDataView::defineOwnProperty(
+ JSObject* object, ExecState* exec, PropertyName propertyName,
+ const PropertyDescriptor& descriptor, bool shouldThrow)
+{
+ JSDataView* thisObject = jsCast<JSDataView*>(object);
+ if (propertyName == exec->propertyNames().byteLength
+ || propertyName == exec->propertyNames().byteOffset)
+ return reject(exec, shouldThrow, "Attempting to define read-only typed array property.");
+
+ return Base::defineOwnProperty(thisObject, exec, propertyName, descriptor, shouldThrow);
+}
+
+bool JSDataView::deleteProperty(
+ JSCell* cell, ExecState* exec, PropertyName propertyName)
+{
+ JSDataView* thisObject = jsCast<JSDataView*>(cell);
+ if (propertyName == exec->propertyNames().byteLength
+ || propertyName == exec->propertyNames().byteOffset)
+ return false;
+
+ return Base::deleteProperty(thisObject, exec, propertyName);
+}
+
+void JSDataView::getOwnNonIndexPropertyNames(
+ JSObject* object, ExecState* exec, PropertyNameArray& array, EnumerationMode mode)
+{
+ JSDataView* thisObject = jsCast<JSDataView*>(object);
+
+ if (mode.includeDontEnumProperties()) {
+ array.add(exec->propertyNames().byteOffset);
+ array.add(exec->propertyNames().byteLength);
+ }
+
+ Base::getOwnNonIndexPropertyNames(thisObject, exec, array, mode);
+}
+
ArrayBuffer* JSDataView::slowDownAndWasteMemory(JSArrayBufferView*)
{
UNREACHABLE_FOR_PLATFORM();
@@ -113,7 +177,7 @@ Structure* JSDataView::createStructure(
VM& vm, JSGlobalObject* globalObject, JSValue prototype)
{
return Structure::create(
- vm, globalObject, prototype, TypeInfo(ObjectType, StructureFlags), info(),
+ vm, globalObject, prototype, TypeInfo(DataViewType, StructureFlags), info(),
NonArray);
}