summaryrefslogtreecommitdiff
path: root/Source/JavaScriptCore/runtime/JSCJSValue.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Source/JavaScriptCore/runtime/JSCJSValue.cpp')
-rw-r--r--Source/JavaScriptCore/runtime/JSCJSValue.cpp142
1 files changed, 21 insertions, 121 deletions
diff --git a/Source/JavaScriptCore/runtime/JSCJSValue.cpp b/Source/JavaScriptCore/runtime/JSCJSValue.cpp
index b9dd0a417..cca6888bf 100644
--- a/Source/JavaScriptCore/runtime/JSCJSValue.cpp
+++ b/Source/JavaScriptCore/runtime/JSCJSValue.cpp
@@ -25,7 +25,6 @@
#include "BooleanConstructor.h"
#include "BooleanPrototype.h"
-#include "CustomGetterSetter.h"
#include "Error.h"
#include "ExceptionHelpers.h"
#include "GetterSetter.h"
@@ -34,7 +33,6 @@
#include "JSGlobalObject.h"
#include "JSNotAnObject.h"
#include "NumberObject.h"
-#include "StructureInlines.h"
#include <wtf/MathExtras.h>
#include <wtf/StringExtras.h>
@@ -56,18 +54,6 @@ double JSValue::toIntegerPreserveNaN(ExecState* exec) const
return trunc(toNumber(exec));
}
-double JSValue::toLength(ExecState* exec) const
-{
- // ECMA 7.1.15
- // http://www.ecma-international.org/ecma-262/6.0/#sec-tolength
- double d = toInteger(exec);
- if (d <= 0)
- return 0.0;
- if (std::isinf(d))
- return 9007199254740991.0; // 2 ** 53 - 1
- return std::min(d, 9007199254740991.0);
-}
-
double JSValue::toNumberSlowCase(ExecState* exec) const
{
ASSERT(!isInt32() && !isDouble());
@@ -75,7 +61,7 @@ double JSValue::toNumberSlowCase(ExecState* exec) const
return asCell()->toNumber(exec);
if (isTrue())
return 1.0;
- return isUndefined() ? PNaN : 0; // null and false both convert to 0.
+ return isUndefined() ? QNaN : 0; // null and false both convert to 0.
}
JSObject* JSValue::toObjectSlowCase(ExecState* exec, JSGlobalObject* globalObject) const
@@ -111,10 +97,8 @@ JSValue JSValue::toThisSlowCase(ExecState* exec, ECMAMode ecmaMode) const
JSObject* JSValue::synthesizePrototype(ExecState* exec) const
{
if (isCell()) {
- if (isString())
- return exec->lexicalGlobalObject()->stringPrototype();
- ASSERT(isSymbol());
- return exec->lexicalGlobalObject()->symbolPrototype();
+ ASSERT(isString());
+ return exec->lexicalGlobalObject()->stringPrototype();
}
if (isNumber())
@@ -133,8 +117,9 @@ void JSValue::putToPrimitive(ExecState* exec, PropertyName propertyName, JSValue
{
VM& vm = exec->vm();
- if (Optional<uint32_t> index = parseIndex(propertyName)) {
- putToPrimitiveByIndex(exec, index.value(), value, slot.isStrictMode());
+ unsigned index = propertyName.asIndex();
+ if (index != PropertyName::NotAnIndex) {
+ putToPrimitiveByIndex(exec, index, value, slot.isStrictMode());
return;
}
@@ -154,7 +139,8 @@ void JSValue::putToPrimitive(ExecState* exec, PropertyName propertyName, JSValue
for (; ; obj = asObject(prototype)) {
unsigned attributes;
- PropertyOffset offset = obj->structure()->get(vm, propertyName, attributes);
+ JSCell* specificValue;
+ PropertyOffset offset = obj->structure()->get(vm, propertyName, attributes, specificValue);
if (offset != invalidOffset) {
if (attributes & ReadOnly) {
if (slot.isStrictMode())
@@ -168,11 +154,6 @@ void JSValue::putToPrimitive(ExecState* exec, PropertyName propertyName, JSValue
return;
}
- if (gs.isCustomGetterSetter()) {
- callCustomSetter(exec, gs, attributes & CustomAccessor, obj, slot.thisValue(), value);
- return;
- }
-
// If there's an existing property on the object or one of its
// prototypes it should be replaced, so break here.
break;
@@ -210,13 +191,6 @@ void JSValue::dump(PrintStream& out) const
void JSValue::dumpInContext(PrintStream& out, DumpContext* context) const
{
- dumpInContextAssumingStructure(
- out, context, (!!*this && isCell()) ? asCell()->structure() : nullptr);
-}
-
-void JSValue::dumpInContextAssumingStructure(
- PrintStream& out, DumpContext* context, Structure* structure) const
-{
if (!*this)
out.print("<JSValue()>");
else if (isInt32())
@@ -233,7 +207,7 @@ void JSValue::dumpInContextAssumingStructure(
out.printf("Double: %08x:%08x, %lf", u.asTwoInt32s[1], u.asTwoInt32s[0], asDouble());
#endif
} else if (isCell()) {
- if (structure->classInfo()->isSubClassOf(JSString::info())) {
+ if (asCell()->inherits(JSString::info())) {
JSString* string = jsCast<JSString*>(asCell());
out.print("String");
if (string->isRope())
@@ -242,62 +216,18 @@ void JSValue::dumpInContextAssumingStructure(
if (impl) {
if (impl->isAtomic())
out.print(" (atomic)");
- if (impl->isAtomic())
+ if (impl->isIdentifier())
out.print(" (identifier)");
- if (impl->isSymbol())
- out.print(" (symbol)");
+ if (impl->isEmptyUnique())
+ out.print(" (unique)");
} else
out.print(" (unresolved)");
out.print(": ", impl);
- } else if (structure->classInfo()->isSubClassOf(Structure::info()))
+ } else if (asCell()->inherits(Structure::info()))
out.print("Structure: ", inContext(*jsCast<Structure*>(asCell()), context));
else {
out.print("Cell: ", RawPointer(asCell()));
- out.print(" (", inContext(*structure, context), ")");
- }
-#if USE(JSVALUE64)
- out.print(", ID: ", asCell()->structureID());
-#endif
- } else if (isTrue())
- out.print("True");
- else if (isFalse())
- out.print("False");
- else if (isNull())
- out.print("Null");
- else if (isUndefined())
- out.print("Undefined");
- else
- out.print("INVALID");
-}
-
-void JSValue::dumpForBacktrace(PrintStream& out) const
-{
- if (!*this)
- out.print("<JSValue()>");
- else if (isInt32())
- out.printf("%d", asInt32());
- else if (isDouble())
- out.printf("%lf", asDouble());
- else if (isCell()) {
- if (asCell()->inherits(JSString::info())) {
- JSString* string = jsCast<JSString*>(asCell());
- const StringImpl* impl = string->tryGetValueImpl();
- if (impl)
- out.print("\"", impl, "\"");
- else
- out.print("(unresolved string)");
- } else if (asCell()->inherits(Structure::info())) {
- out.print("Structure[ ", asCell()->structure()->classInfo()->className);
-#if USE(JSVALUE64)
- out.print(" ID: ", asCell()->structureID());
-#endif
- out.print("]: ", RawPointer(asCell()));
- } else {
- out.print("Cell[", asCell()->structure()->classInfo()->className);
-#if USE(JSVALUE64)
- out.print(" ID: ", asCell()->structureID());
-#endif
- out.print("]: ", RawPointer(asCell()));
+ out.print(" (", inContext(*asCell()->structure(), context), ")");
}
} else if (isTrue())
out.print("True");
@@ -361,22 +291,12 @@ bool JSValue::isValidCallee()
return asObject(asCell())->globalObject();
}
-JSString* JSValue::toStringSlowCase(ExecState* exec, bool returnEmptyStringOnError) const
+JSString* JSValue::toStringSlowCase(ExecState* exec) const
{
- auto errorValue = [&] () -> JSString* {
- if (returnEmptyStringOnError)
- return jsEmptyString(exec);
- return nullptr;
- };
-
VM& vm = exec->vm();
ASSERT(!isString());
- if (isInt32()) {
- auto integer = asInt32();
- if (static_cast<unsigned>(integer) <= 9)
- return vm.smallStrings.singleCharacterString(integer + '0');
- return jsNontrivialString(&vm, vm.numericStrings.add(integer));
- }
+ if (isInt32())
+ return jsString(&vm, vm.numericStrings.add(asInt32()));
if (isDouble())
return jsString(&vm, vm.numericStrings.add(asDouble()));
if (isTrue())
@@ -387,38 +307,18 @@ JSString* JSValue::toStringSlowCase(ExecState* exec, bool returnEmptyStringOnErr
return vm.smallStrings.nullString();
if (isUndefined())
return vm.smallStrings.undefinedString();
- if (isSymbol()) {
- throwTypeError(exec);
- return errorValue();
- }
ASSERT(isCell());
JSValue value = asCell()->toPrimitive(exec, PreferString);
- if (vm.exception())
- return errorValue();
+ if (exec->hadException())
+ return jsEmptyString(exec);
ASSERT(!value.isObject());
- JSString* result = value.toString(exec);
- if (vm.exception())
- return errorValue();
- return result;
+ return value.toString(exec);
}
String JSValue::toWTFStringSlowCase(ExecState* exec) const
{
- VM& vm = exec->vm();
- if (isInt32())
- return vm.numericStrings.add(asInt32());
- if (isDouble())
- return vm.numericStrings.add(asDouble());
- if (isTrue())
- return vm.propertyNames->trueKeyword.string();
- if (isFalse())
- return vm.propertyNames->falseKeyword.string();
- if (isNull())
- return vm.propertyNames->nullKeyword.string();
- if (isUndefined())
- return vm.propertyNames->undefinedKeyword.string();
- return toString(exec)->value(exec);
+ return inlineJSValueNotStringtoString(*this, exec);
}
} // namespace JSC