1/*
2 * Copyright (C) 1999-2001 Harri Porten (porten@kde.org)
3 * Copyright (C) 2001 Peter Kelly (pmk@post.com)
4 * Copyright (C) 2003-2006, 2008, 2009, 2012-2015 Apple Inc. All rights reserved.
5 * Copyright (C) 2007 Eric Seidel (eric@webkit.org)
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
16 *
17 * You should have received a copy of the GNU Library General Public License
18 * along with this library; see the file COPYING.LIB. If not, write to
19 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 * Boston, MA 02110-1301, USA.
21 *
22 */
23
24#ifndef JSObjectInlines_h
25#define JSObjectInlines_h
26
27#include "Error.h"
28#include "JSObject.h"
29#include "Lookup.h"
30
31namespace JSC {
32
33// ECMA 8.6.2.2
34ALWAYS_INLINE void JSObject::putInline(JSCell* cell, ExecState* exec, PropertyName propertyName, JSValue value, PutPropertySlot& slot)
35{
36 JSObject* thisObject = jsCast<JSObject*>(cell);
37 ASSERT(value);
38 ASSERT(!Heap::heap(value) || Heap::heap(value) == Heap::heap(thisObject));
39 VM& vm = exec->vm();
40
41 // Try indexed put first. This is required for correctness, since loads on property names that appear like
42 // valid indices will never look in the named property storage.
43 if (Optional<uint32_t> index = parseIndex(propertyName)) {
44 putByIndex(thisObject, exec, index.value(), value, slot.isStrictMode());
45 return;
46 }
47
48 // Check if there are any setters or getters in the prototype chain
49 JSValue prototype;
50 if (propertyName != exec->propertyNames().underscoreProto) {
51 for (JSObject* obj = thisObject; !obj->structure(vm)->hasReadOnlyOrGetterSetterPropertiesExcludingProto(); obj = asObject(prototype)) {
52 prototype = obj->prototype();
53 if (prototype.isNull()) {
54 ASSERT(!thisObject->structure(vm)->prototypeChainMayInterceptStoreTo(exec->vm(), propertyName));
55 if (!thisObject->putDirectInternal<PutModePut>(vm, propertyName, value, 0, slot)
56 && slot.isStrictMode())
57 throwTypeError(exec, ASCIILiteral(StrictModeReadonlyPropertyWriteError));
58 return;
59 }
60 }
61 }
62
63 thisObject->putInlineSlow(exec, propertyName, value, slot);
64}
65
66} // namespace JSC
67
68#endif // JSObjectInlines_h
69
70