2 * Copyright (C) 2013 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
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.
27 #include "JSArrayBuffer.h"
29 #include "JSCInlines.h"
34 const ClassInfo
JSArrayBuffer::s_info
= {
35 "ArrayBuffer", &Base::s_info
, 0, 0, CREATE_METHOD_TABLE(JSArrayBuffer
)};
37 JSArrayBuffer::JSArrayBuffer(VM
& vm
, Structure
* structure
, PassRefPtr
<ArrayBuffer
> arrayBuffer
)
39 , m_impl(arrayBuffer
.get())
43 void JSArrayBuffer::finishCreation(VM
& vm
)
45 Base::finishCreation(vm
);
46 vm
.heap
.addReference(this, m_impl
);
49 JSArrayBuffer
* JSArrayBuffer::create(
50 VM
& vm
, Structure
* structure
, PassRefPtr
<ArrayBuffer
> passedBuffer
)
52 RefPtr
<ArrayBuffer
> buffer
= passedBuffer
;
53 JSArrayBuffer
* result
=
54 new (NotNull
, allocateCell
<JSArrayBuffer
>(vm
.heap
))
55 JSArrayBuffer(vm
, structure
, buffer
);
56 result
->finishCreation(vm
);
60 Structure
* JSArrayBuffer::createStructure(
61 VM
& vm
, JSGlobalObject
* globalObject
, JSValue prototype
)
63 return Structure::create(
64 vm
, globalObject
, prototype
, TypeInfo(ObjectType
, StructureFlags
), info(),
68 bool JSArrayBuffer::getOwnPropertySlot(
69 JSObject
* object
, ExecState
* exec
, PropertyName propertyName
, PropertySlot
& slot
)
71 JSArrayBuffer
* thisObject
= jsCast
<JSArrayBuffer
*>(object
);
73 if (propertyName
== exec
->propertyNames().byteLength
) {
74 slot
.setValue(thisObject
, DontDelete
| ReadOnly
, jsNumber(thisObject
->impl()->byteLength()));
78 return Base::getOwnPropertySlot(thisObject
, exec
, propertyName
, slot
);
81 void JSArrayBuffer::put(
82 JSCell
* cell
, ExecState
* exec
, PropertyName propertyName
, JSValue value
,
83 PutPropertySlot
& slot
)
85 JSArrayBuffer
* thisObject
= jsCast
<JSArrayBuffer
*>(cell
);
87 if (propertyName
== exec
->propertyNames().byteLength
) {
88 reject(exec
, slot
.isStrictMode(), "Attempting to write to a read-only array buffer property.");
92 Base::put(thisObject
, exec
, propertyName
, value
, slot
);
95 bool JSArrayBuffer::defineOwnProperty(
96 JSObject
* object
, ExecState
* exec
, PropertyName propertyName
,
97 const PropertyDescriptor
& descriptor
, bool shouldThrow
)
99 JSArrayBuffer
* thisObject
= jsCast
<JSArrayBuffer
*>(object
);
101 if (propertyName
== exec
->propertyNames().byteLength
)
102 return reject(exec
, shouldThrow
, "Attempting to define read-only array buffer property.");
104 return Base::defineOwnProperty(thisObject
, exec
, propertyName
, descriptor
, shouldThrow
);
107 bool JSArrayBuffer::deleteProperty(JSCell
* cell
, ExecState
* exec
, PropertyName propertyName
)
109 JSArrayBuffer
* thisObject
= jsCast
<JSArrayBuffer
*>(cell
);
111 if (propertyName
== exec
->propertyNames().byteLength
)
114 return Base::deleteProperty(thisObject
, exec
, propertyName
);
117 void JSArrayBuffer::getOwnNonIndexPropertyNames(
118 JSObject
* object
, ExecState
* exec
, PropertyNameArray
& array
, EnumerationMode mode
)
120 JSArrayBuffer
* thisObject
= jsCast
<JSArrayBuffer
*>(object
);
122 if (mode
== IncludeDontEnumProperties
)
123 array
.add(exec
->propertyNames().byteLength
);
125 Base::getOwnNonIndexPropertyNames(thisObject
, exec
, array
, mode
);