diff options
Diffstat (limited to 'Source/JavaScriptCore/runtime/Operations.h')
-rw-r--r-- | Source/JavaScriptCore/runtime/Operations.h | 97 |
1 files changed, 18 insertions, 79 deletions
diff --git a/Source/JavaScriptCore/runtime/Operations.h b/Source/JavaScriptCore/runtime/Operations.h index e628662e0..057f59471 100644 --- a/Source/JavaScriptCore/runtime/Operations.h +++ b/Source/JavaScriptCore/runtime/Operations.h @@ -1,6 +1,6 @@ /* * Copyright (C) 1999-2000 Harri Porten (porten@kde.org) - * Copyright (C) 2002, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved. + * Copyright (C) 2002, 2005, 2006, 2007, 2008, 2009, 2013, 2014 Apple Inc. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -22,20 +22,16 @@ #ifndef Operations_h #define Operations_h +#include "CallFrame.h" #include "ExceptionHelpers.h" -#include "Interpreter.h" -#include "JSCJSValueInlines.h" -#include "JSFunctionInlines.h" -#include "JSProxy.h" -#include "JSString.h" -#include "StructureInlines.h" +#include "JSCJSValue.h" namespace JSC { NEVER_INLINE JSValue jsAddSlowCase(CallFrame*, JSValue, JSValue); JSValue jsTypeStringForValue(CallFrame*, JSValue); JSValue jsTypeStringForValue(VM&, JSGlobalObject*, JSValue); -bool jsIsObjectType(CallFrame*, JSValue); +bool jsIsObjectTypeOrNull(CallFrame*, JSValue); bool jsIsFunctionType(JSValue); ALWAYS_INLINE JSValue jsString(ExecState* exec, JSString* s1, JSString* s2) @@ -48,7 +44,7 @@ ALWAYS_INLINE JSValue jsString(ExecState* exec, JSString* s1, JSString* s2) int32_t length2 = s2->length(); if (!length2) return s1; - if ((length1 + length2) < 0) + if (sumOverflows<int32_t>(length1, length2)) return throwOutOfMemoryError(exec); return JSRopeString::create(vm, s1, s2); @@ -61,10 +57,10 @@ ALWAYS_INLINE JSValue jsString(ExecState* exec, const String& u1, const String& int32_t length1 = u1.length(); int32_t length2 = u2.length(); int32_t length3 = u3.length(); - + if (length1 < 0 || length2 < 0 || length3 < 0) return throwOutOfMemoryError(exec); - + if (!length1) return jsString(exec, jsString(vm, u2), jsString(vm, u3)); if (!length2) @@ -72,22 +68,19 @@ ALWAYS_INLINE JSValue jsString(ExecState* exec, const String& u1, const String& if (!length3) return jsString(exec, jsString(vm, u1), jsString(vm, u2)); - if ((length1 + length2) < 0) - return throwOutOfMemoryError(exec); - if ((length1 + length2 + length3) < 0) + if (sumOverflows<int32_t>(length1, length2, length3)) return throwOutOfMemoryError(exec); return JSRopeString::create(exec->vm(), jsString(vm, u1), jsString(vm, u2), jsString(vm, u3)); } -ALWAYS_INLINE JSValue jsString(ExecState* exec, Register* strings, unsigned count) +ALWAYS_INLINE JSValue jsStringFromRegisterArray(ExecState* exec, Register* strings, unsigned count) { VM* vm = &exec->vm(); JSRopeString::RopeBuilder ropeBuilder(*vm); for (unsigned i = 0; i < count; ++i) { - JSValue v = strings[i].jsValue(); - + JSValue v = strings[-static_cast<int>(i)].jsValue(); if (!ropeBuilder.append(v.toString(exec))) return throwOutOfMemoryError(exec); } @@ -201,82 +194,28 @@ ALWAYS_INLINE JSValue jsAdd(CallFrame* callFrame, JSValue v1, JSValue v2) #define InvalidPrototypeChain (std::numeric_limits<size_t>::max()) -inline size_t normalizePrototypeChainForChainAccess(CallFrame* callFrame, JSValue base, JSValue slotBase, const Identifier& propertyName, PropertyOffset& slotOffset) -{ - JSCell* cell = base.asCell(); - size_t count = 0; - - while (slotBase != cell) { - if (cell->isProxy()) - return InvalidPrototypeChain; - - if (cell->structure()->typeInfo().hasImpureGetOwnPropertySlot()) - return InvalidPrototypeChain; - - JSValue v = cell->structure()->prototypeForLookup(callFrame); - - // If we didn't find slotBase in base's prototype chain, then base - // must be a proxy for another object. - - if (v.isNull()) - return InvalidPrototypeChain; - - cell = v.asCell(); - - // Since we're accessing a prototype in a loop, it's a good bet that it - // should not be treated as a dictionary. - if (cell->structure()->isDictionary()) { - asObject(cell)->flattenDictionaryObject(callFrame->vm()); - if (slotBase == cell) - slotOffset = cell->structure()->get(callFrame->vm(), propertyName); - } - - ++count; - } - - ASSERT(count); - return count; -} - -inline size_t normalizePrototypeChain(CallFrame* callFrame, JSCell* base) +inline size_t normalizePrototypeChain(CallFrame* callFrame, Structure* structure) { + VM& vm = callFrame->vm(); size_t count = 0; while (1) { - if (base->isProxy()) + if (structure->isProxy()) return InvalidPrototypeChain; - - JSValue v = base->structure()->prototypeForLookup(callFrame); + JSValue v = structure->prototypeForLookup(callFrame); if (v.isNull()) return count; - base = v.asCell(); - + JSCell* base = v.asCell(); + structure = base->structure(vm); // Since we're accessing a prototype in a loop, it's a good bet that it // should not be treated as a dictionary. - if (base->structure()->isDictionary()) - asObject(base)->flattenDictionaryObject(callFrame->vm()); + if (structure->isDictionary()) + structure->flattenDictionaryStructure(vm, asObject(base)); ++count; } } -inline bool isPrototypeChainNormalized(JSGlobalObject* globalObject, Structure* structure) -{ - for (;;) { - if (structure->typeInfo().type() == ProxyType) - return false; - - JSValue v = structure->prototypeForLookup(globalObject); - if (v.isNull()) - return true; - - structure = v.asCell()->structure(); - - if (structure->isDictionary()) - return false; - } -} - } // namespace JSC #endif // Operations_h |