X-Git-Url: https://git.saurik.com/apple/javascriptcore.git/blobdiff_plain/2d39b0e377c0896910ee49ae70082ba665faf986..refs/heads/master:/runtime/JSCJSValue.h diff --git a/runtime/JSCJSValue.h b/runtime/JSCJSValue.h index 514c4d9..039c14e 100644 --- a/runtime/JSCJSValue.h +++ b/runtime/JSCJSValue.h @@ -32,6 +32,7 @@ #include #include #include +#include #include #include @@ -45,9 +46,11 @@ class VM; class JSGlobalObject; class JSObject; class JSString; +class Identifier; class PropertyName; class PropertySlot; class PutPropertySlot; +class Structure; #if ENABLE(DFG_JIT) namespace DFG { class JITCompiler; @@ -122,8 +125,15 @@ inline uint32_t toUInt32(double number) int64_t tryConvertToInt52(double); bool isInt52(double); +enum class SourceCodeRepresentation { + Other, + Integer, + Double +}; + class JSValue { friend struct EncodedJSValueHashTraits; + friend struct EncodedJSValueWithRepresentationHashTraits; friend class AssemblyHelpers; friend class JIT; friend class JITSlowPathCall; @@ -185,8 +195,7 @@ public: explicit JSValue(long long); explicit JSValue(unsigned long long); - typedef void* (JSValue::*UnspecifiedBoolType); - operator UnspecifiedBoolType*() const; + explicit operator bool() const; bool operator==(const JSValue& other) const; bool operator!=(const JSValue& other) const; @@ -215,6 +224,7 @@ public: bool isMachineInt() const; bool isNumber() const; bool isString() const; + bool isSymbol() const; bool isPrimitive() const; bool isGetterSetter() const; bool isCustomGetterSetter() const; @@ -240,19 +250,19 @@ public: // been set in the ExecState already. double toNumber(ExecState*) const; JSString* toString(ExecState*) const; + Identifier toPropertyKey(ExecState*) const; WTF::String toWTFString(ExecState*) const; - WTF::String toWTFStringInline(ExecState*) const; JSObject* toObject(ExecState*) const; JSObject* toObject(ExecState*, JSGlobalObject*) const; // Integer conversions. JS_EXPORT_PRIVATE double toInteger(ExecState*) const; - double toIntegerPreserveNaN(ExecState*) const; + JS_EXPORT_PRIVATE double toIntegerPreserveNaN(ExecState*) const; int32_t toInt32(ExecState*) const; uint32_t toUInt32(ExecState*) const; - // Floating point conversions (this is a convenience method for webcore; - // signle precision float is not a representation used in JS or JSC). + // Floating point conversions (this is a convenience function for WebCore; + // single precision float is not a representation used in JS or JSC). float toFloat(ExecState* exec) const { return static_cast(toNumber(exec)); } // Object operations, with the toObject operation included. @@ -260,9 +270,12 @@ public: JSValue get(ExecState*, PropertyName, PropertySlot&) const; JSValue get(ExecState*, unsigned propertyName) const; JSValue get(ExecState*, unsigned propertyName, PropertySlot&) const; + + bool getPropertySlot(ExecState*, PropertyName, PropertySlot&) const; + void put(ExecState*, PropertyName, JSValue, PutPropertySlot&); - void putToPrimitive(ExecState*, PropertyName, JSValue, PutPropertySlot&); - void putToPrimitiveByIndex(ExecState*, unsigned propertyName, JSValue, bool shouldThrow); + JS_EXPORT_PRIVATE void putToPrimitive(ExecState*, PropertyName, JSValue, PutPropertySlot&); + JS_EXPORT_PRIVATE void putToPrimitiveByIndex(ExecState*, unsigned propertyName, JSValue, bool shouldThrow); void putByIndex(ExecState*, unsigned propertyName, JSValue, bool shouldThrow); JSValue toThis(ExecState*, ECMAMode) const; @@ -283,9 +296,11 @@ public: JS_EXPORT_PRIVATE void dump(PrintStream&) const; void dumpInContext(PrintStream&, DumpContext*) const; + void dumpInContextAssumingStructure(PrintStream&, DumpContext*, Structure*) const; void dumpForBacktrace(PrintStream&) const; JS_EXPORT_PRIVATE JSObject* synthesizePrototype(ExecState*) const; + bool requireObjectCoercible(ExecState*) const; // Constants used for Int52. Int52 isn't part of JSValue right now, but JSValues may be // converted to Int52s and back again. @@ -440,7 +455,26 @@ struct EncodedJSValueHashTraits : HashTraits { }; #endif -typedef HashMap JSValueMap; +typedef std::pair EncodedJSValueWithRepresentation; + +struct EncodedJSValueWithRepresentationHashTraits : HashTraits { + static const bool emptyValueIsZero = false; + static EncodedJSValueWithRepresentation emptyValue() { return std::make_pair(JSValue::encode(JSValue()), SourceCodeRepresentation::Other); } + static void constructDeletedValue(EncodedJSValueWithRepresentation& slot) { slot = std::make_pair(JSValue::encode(JSValue(JSValue::HashTableDeletedValue)), SourceCodeRepresentation::Other); } + static bool isDeletedValue(EncodedJSValueWithRepresentation value) { return value == std::make_pair(JSValue::encode(JSValue(JSValue::HashTableDeletedValue)), SourceCodeRepresentation::Other); } +}; + +struct EncodedJSValueWithRepresentationHash { + static unsigned hash(const EncodedJSValueWithRepresentation& value) + { + return WTF::pairIntHash(EncodedJSValueHash::hash(value.first), IntHash::hash(value.second)); + } + static bool equal(const EncodedJSValueWithRepresentation& a, const EncodedJSValueWithRepresentation& b) + { + return a == b; + } + static const bool safeToCompareToEmptyOrDeleted = true; +}; // Stand-alone helper functions. inline JSValue jsNull() @@ -470,6 +504,11 @@ ALWAYS_INLINE JSValue jsNumber(double d) return JSValue(d); } +ALWAYS_INLINE JSValue jsNumber(MediaTime t) +{ + return jsNumber(t.toDouble()); +} + ALWAYS_INLINE JSValue jsNumber(char i) { return JSValue(i);