]>
Commit | Line | Data |
---|---|---|
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 | ||
32 | namespace JSC { | |
33 | ||
34 | const ClassInfo JSArrayBuffer::s_info = { | |
35 | "ArrayBuffer", &Base::s_info, 0, 0, CREATE_METHOD_TABLE(JSArrayBuffer)}; | |
36 | ||
37 | JSArrayBuffer::JSArrayBuffer(VM& vm, Structure* structure, PassRefPtr<ArrayBuffer> arrayBuffer) | |
38 | : Base(vm, structure) | |
39 | , m_impl(arrayBuffer.get()) | |
40 | { | |
41 | } | |
42 | ||
43 | void JSArrayBuffer::finishCreation(VM& vm) | |
44 | { | |
45 | Base::finishCreation(vm); | |
46 | vm.heap.addReference(this, m_impl); | |
47 | } | |
48 | ||
49 | JSArrayBuffer* 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 | ||
60 | Structure* 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 | ||
68 | bool 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 | ||
81 | void 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 | ||
95 | bool 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 | ||
107 | bool 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 | ||
117 | void 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 |