]> git.saurik.com Git - apple/javascriptcore.git/blame - runtime/JSArrayBuffer.cpp
JavaScriptCore-7600.1.4.16.1.tar.gz
[apple/javascriptcore.git] / runtime / JSArrayBuffer.cpp
CommitLineData
81345200
A
1/*
2 * Copyright (C) 2013 Apple Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26#include "config.h"
27#include "JSArrayBuffer.h"
28
29#include "JSCInlines.h"
30#include "Reject.h"
31
32namespace JSC {
33
34const ClassInfo JSArrayBuffer::s_info = {
35 "ArrayBuffer", &Base::s_info, 0, 0, CREATE_METHOD_TABLE(JSArrayBuffer)};
36
37JSArrayBuffer::JSArrayBuffer(VM& vm, Structure* structure, PassRefPtr<ArrayBuffer> arrayBuffer)
38 : Base(vm, structure)
39 , m_impl(arrayBuffer.get())
40{
41}
42
43void JSArrayBuffer::finishCreation(VM& vm)
44{
45 Base::finishCreation(vm);
46 vm.heap.addReference(this, m_impl);
47}
48
49JSArrayBuffer* JSArrayBuffer::create(
50 VM& vm, Structure* structure, PassRefPtr<ArrayBuffer> passedBuffer)
51{
52 RefPtr<ArrayBuffer> buffer = passedBuffer;
53 JSArrayBuffer* result =
54 new (NotNull, allocateCell<JSArrayBuffer>(vm.heap))
55 JSArrayBuffer(vm, structure, buffer);
56 result->finishCreation(vm);
57 return result;
58}
59
60Structure* JSArrayBuffer::createStructure(
61 VM& vm, JSGlobalObject* globalObject, JSValue prototype)
62{
63 return Structure::create(
64 vm, globalObject, prototype, TypeInfo(ObjectType, StructureFlags), info(),
65 NonArray);
66}
67
68bool JSArrayBuffer::getOwnPropertySlot(
69 JSObject* object, ExecState* exec, PropertyName propertyName, PropertySlot& slot)
70{
71 JSArrayBuffer* thisObject = jsCast<JSArrayBuffer*>(object);
72
73 if (propertyName == exec->propertyNames().byteLength) {
74 slot.setValue(thisObject, DontDelete | ReadOnly, jsNumber(thisObject->impl()->byteLength()));
75 return true;
76 }
77
78 return Base::getOwnPropertySlot(thisObject, exec, propertyName, slot);
79}
80
81void JSArrayBuffer::put(
82 JSCell* cell, ExecState* exec, PropertyName propertyName, JSValue value,
83 PutPropertySlot& slot)
84{
85 JSArrayBuffer* thisObject = jsCast<JSArrayBuffer*>(cell);
86
87 if (propertyName == exec->propertyNames().byteLength) {
88 reject(exec, slot.isStrictMode(), "Attempting to write to a read-only array buffer property.");
89 return;
90 }
91
92 Base::put(thisObject, exec, propertyName, value, slot);
93}
94
95bool JSArrayBuffer::defineOwnProperty(
96 JSObject* object, ExecState* exec, PropertyName propertyName,
97 const PropertyDescriptor& descriptor, bool shouldThrow)
98{
99 JSArrayBuffer* thisObject = jsCast<JSArrayBuffer*>(object);
100
101 if (propertyName == exec->propertyNames().byteLength)
102 return reject(exec, shouldThrow, "Attempting to define read-only array buffer property.");
103
104 return Base::defineOwnProperty(thisObject, exec, propertyName, descriptor, shouldThrow);
105}
106
107bool JSArrayBuffer::deleteProperty(JSCell* cell, ExecState* exec, PropertyName propertyName)
108{
109 JSArrayBuffer* thisObject = jsCast<JSArrayBuffer*>(cell);
110
111 if (propertyName == exec->propertyNames().byteLength)
112 return false;
113
114 return Base::deleteProperty(thisObject, exec, propertyName);
115}
116
117void JSArrayBuffer::getOwnNonIndexPropertyNames(
118 JSObject* object, ExecState* exec, PropertyNameArray& array, EnumerationMode mode)
119{
120 JSArrayBuffer* thisObject = jsCast<JSArrayBuffer*>(object);
121
122 if (mode == IncludeDontEnumProperties)
123 array.add(exec->propertyNames().byteLength);
124
125 Base::getOwnNonIndexPropertyNames(thisObject, exec, array, mode);
126}
127
128} // namespace JSC
129