diff options
Diffstat (limited to 'Source/JavaScriptCore/runtime')
-rw-r--r-- | Source/JavaScriptCore/runtime/ArrayConstructor.cpp | 19 | ||||
-rw-r--r-- | Source/JavaScriptCore/runtime/ArrayConstructor.h | 3 | ||||
-rw-r--r-- | Source/JavaScriptCore/runtime/CommonIdentifiers.h | 2 | ||||
-rw-r--r-- | Source/JavaScriptCore/runtime/JSGlobalObject.cpp | 6 | ||||
-rw-r--r-- | Source/JavaScriptCore/runtime/StringPrototype.cpp | 20 |
5 files changed, 35 insertions, 15 deletions
diff --git a/Source/JavaScriptCore/runtime/ArrayConstructor.cpp b/Source/JavaScriptCore/runtime/ArrayConstructor.cpp index a13648442..5c2cd7167 100644 --- a/Source/JavaScriptCore/runtime/ArrayConstructor.cpp +++ b/Source/JavaScriptCore/runtime/ArrayConstructor.cpp @@ -77,17 +77,24 @@ bool ArrayConstructor::getOwnPropertyDescriptor(JSObject* object, ExecState* exe // ------------------------------ Functions --------------------------- +JSObject* constructArrayWithSizeQuirk(ExecState* exec, JSGlobalObject* globalObject, JSValue length) +{ + if (!length.isNumber()) + return constructArray(exec, globalObject, &length, 1); + + uint32_t n = length.toUInt32(exec); + if (n != length.toNumber(exec)) + return throwError(exec, createRangeError(exec, ASCIILiteral("Array size is not a small enough positive integer."))); + return constructEmptyArray(exec, globalObject, n); +} + static inline JSObject* constructArrayWithSizeQuirk(ExecState* exec, const ArgList& args) { JSGlobalObject* globalObject = asInternalFunction(exec->callee())->globalObject(); // a single numeric argument denotes the array size (!) - if (args.size() == 1 && args.at(0).isNumber()) { - uint32_t n = args.at(0).toUInt32(exec); - if (n != args.at(0).toNumber(exec)) - return throwError(exec, createRangeError(exec, ASCIILiteral("Array size is not a small enough positive integer."))); - return constructEmptyArray(exec, globalObject, n); - } + if (args.size() == 1) + return constructArrayWithSizeQuirk(exec, globalObject, args.at(0)); // otherwise the array is constructed with the arguments in it return constructArray(exec, globalObject, args); diff --git a/Source/JavaScriptCore/runtime/ArrayConstructor.h b/Source/JavaScriptCore/runtime/ArrayConstructor.h index b223a0f13..dcbf0a1b3 100644 --- a/Source/JavaScriptCore/runtime/ArrayConstructor.h +++ b/Source/JavaScriptCore/runtime/ArrayConstructor.h @@ -26,6 +26,7 @@ namespace JSC { class ArrayPrototype; + class JSArray; class ArrayConstructor : public InternalFunction { public: @@ -59,6 +60,8 @@ namespace JSC { static CallType getCallData(JSCell*, CallData&); }; + JSObject* constructArrayWithSizeQuirk(ExecState*, JSGlobalObject*, JSValue); + } // namespace JSC #endif // ArrayConstructor_h diff --git a/Source/JavaScriptCore/runtime/CommonIdentifiers.h b/Source/JavaScriptCore/runtime/CommonIdentifiers.h index e15335ef0..ae3b45b8c 100644 --- a/Source/JavaScriptCore/runtime/CommonIdentifiers.h +++ b/Source/JavaScriptCore/runtime/CommonIdentifiers.h @@ -29,6 +29,7 @@ #define JSC_COMMON_IDENTIFIERS_EACH_PROPERTY_NAME(macro) \ macro(apply) \ macro(arguments) \ + macro(Array) \ macro(bind) \ macro(call) \ macro(callee) \ @@ -54,6 +55,7 @@ macro(multiline) \ macro(name) \ macro(now) \ + macro(Object) \ macro(parse) \ macro(propertyIsEnumerable) \ macro(prototype) \ diff --git a/Source/JavaScriptCore/runtime/JSGlobalObject.cpp b/Source/JavaScriptCore/runtime/JSGlobalObject.cpp index 9eb266135..03252fad1 100644 --- a/Source/JavaScriptCore/runtime/JSGlobalObject.cpp +++ b/Source/JavaScriptCore/runtime/JSGlobalObject.cpp @@ -289,9 +289,9 @@ void JSGlobalObject::reset(JSValue prototype) m_regExpPrototype->putDirectWithoutTransition(exec->globalData(), exec->propertyNames().constructor, m_regExpConstructor.get(), DontEnum); m_errorPrototype->putDirectWithoutTransition(exec->globalData(), exec->propertyNames().constructor, m_errorConstructor.get(), DontEnum); - putDirectWithoutTransition(exec->globalData(), Identifier(exec, "Object"), objectConstructor, DontEnum); + putDirectWithoutTransition(exec->globalData(), exec->propertyNames().Object, objectConstructor, DontEnum); putDirectWithoutTransition(exec->globalData(), Identifier(exec, "Function"), functionConstructor, DontEnum); - putDirectWithoutTransition(exec->globalData(), Identifier(exec, "Array"), arrayConstructor, DontEnum); + putDirectWithoutTransition(exec->globalData(), exec->propertyNames().Array, arrayConstructor, DontEnum); putDirectWithoutTransition(exec->globalData(), Identifier(exec, "Boolean"), booleanConstructor, DontEnum); putDirectWithoutTransition(exec->globalData(), Identifier(exec, "String"), stringConstructor, DontEnum); putDirectWithoutTransition(exec->globalData(), Identifier(exec, "Number"), numberConstructor, DontEnum); @@ -320,6 +320,8 @@ void JSGlobalObject::reset(JSValue prototype) m_specialPointers[Special::CallFunction] = m_callFunction.get(); m_specialPointers[Special::ApplyFunction] = m_applyFunction.get(); + m_specialPointers[Special::ObjectConstructor] = objectConstructor; + m_specialPointers[Special::ArrayConstructor] = arrayConstructor; if (m_experimentsEnabled) { NamePrototype* privateNamePrototype = NamePrototype::create(exec, NamePrototype::createStructure(exec->globalData(), this, m_objectPrototype.get())); diff --git a/Source/JavaScriptCore/runtime/StringPrototype.cpp b/Source/JavaScriptCore/runtime/StringPrototype.cpp index 1540177be..4d3ccfda2 100644 --- a/Source/JavaScriptCore/runtime/StringPrototype.cpp +++ b/Source/JavaScriptCore/runtime/StringPrototype.cpp @@ -280,7 +280,7 @@ static ALWAYS_INLINE JSValue jsSpliceSubstrings(ExecState* exec, JSString* sourc if (position <= 0 && length >= sourceSize) return sourceVal; // We could call String::substringSharingImpl(), but this would result in redundant checks. - return jsString(exec, StringImpl::create(source.impl(), max(0, position), min(sourceSize, length))); + return jsString(exec, StringImpl::create(source.impl(), std::max(0, position), std::min(sourceSize, length))); } int totalLength = 0; @@ -335,7 +335,7 @@ static ALWAYS_INLINE JSValue jsSpliceSubstringsWithSeparators(ExecState* exec, J if (position <= 0 && length >= sourceSize) return sourceVal; // We could call String::substringSharingImpl(), but this would result in redundant checks. - return jsString(exec, StringImpl::create(source.impl(), max(0, position), min(sourceSize, length))); + return jsString(exec, StringImpl::create(source.impl(), std::max(0, position), std::min(sourceSize, length))); } int totalLength = 0; @@ -359,7 +359,7 @@ static ALWAYS_INLINE JSValue jsSpliceSubstringsWithSeparators(ExecState* exec, J if (!impl) return throwOutOfMemoryError(exec); - int maxCount = max(rangeCount, separatorCount); + int maxCount = std::max(rangeCount, separatorCount); int bufferPos = 0; for (int i = 0; i < maxCount; i++) { if (i < rangeCount) { @@ -384,18 +384,24 @@ static ALWAYS_INLINE JSValue jsSpliceSubstringsWithSeparators(ExecState* exec, J if (!impl) return throwOutOfMemoryError(exec); - int maxCount = max(rangeCount, separatorCount); + int maxCount = std::max(rangeCount, separatorCount); int bufferPos = 0; for (int i = 0; i < maxCount; i++) { if (i < rangeCount) { if (int srcLen = substringRanges[i].length) { - StringImpl::copyChars(buffer + bufferPos, source.characters() + substringRanges[i].position, srcLen); + if (source.is8Bit()) + StringImpl::copyChars(buffer + bufferPos, source.characters8() + substringRanges[i].position, srcLen); + else + StringImpl::copyChars(buffer + bufferPos, source.characters16() + substringRanges[i].position, srcLen); bufferPos += srcLen; } } if (i < separatorCount) { if (int sepLen = separators[i].length()) { - StringImpl::copyChars(buffer + bufferPos, separators[i].characters(), sepLen); + if (separators[i].is8Bit()) + StringImpl::copyChars(buffer + bufferPos, separators[i].characters8(), sepLen); + else + StringImpl::copyChars(buffer + bufferPos, separators[i].characters16(), sepLen); bufferPos += sepLen; } } @@ -767,7 +773,7 @@ EncodedJSValue JSC_HOST_CALL stringProtoFuncIndexOf(ExecState* exec) unsigned pos; int len = s.length(); if (a1.isUInt32()) - pos = min<uint32_t>(a1.asUInt32(), len); + pos = std::min<uint32_t>(a1.asUInt32(), len); else { double dpos = a1.toInteger(exec); if (dpos < 0) |