]> git.saurik.com Git - apple/javascriptcore.git/blobdiff - runtime/ErrorInstance.h
JavaScriptCore-1097.13.tar.gz
[apple/javascriptcore.git] / runtime / ErrorInstance.h
index afcf158ad3ae7e70ce384dca44c54e574ef9e85d..d6fa32f99cf3b3dc4b0f1249397f5d607556527d 100644 (file)
@@ -27,26 +27,41 @@ namespace JSC {
 
     class ErrorInstance : public JSNonFinalObject {
     public:
+        typedef JSNonFinalObject Base;
+
         static const ClassInfo s_info;
 
-        static Structure* createStructure(JSGlobalData& globalData, JSValue prototype)
+        static Structure* createStructure(JSGlobalData& globalData, JSGlobalObject* globalObject, JSValue prototype)
         {
-            return Structure::create(globalData, prototype, TypeInfo(ObjectType, StructureFlags), AnonymousSlotCount, &s_info);
+            return Structure::create(globalData, globalObject, prototype, TypeInfo(ErrorInstanceType, StructureFlags), &s_info);
         }
 
-        static ErrorInstance* create(JSGlobalData*, Structure*, const UString&);
-        static ErrorInstance* create(ExecState*, Structure*, JSValue message);
+        static ErrorInstance* create(JSGlobalData& globalData, Structure* structure, const UString& message)
+        {
+            ErrorInstance* instance = new (NotNull, allocateCell<ErrorInstance>(globalData.heap)) ErrorInstance(globalData, structure);
+            instance->finishCreation(globalData, message);
+            return instance;
+        }
 
+        static ErrorInstance* create(ExecState* exec, Structure* structure, JSValue message)
+        {
+            return create(exec->globalData(), structure, message.isUndefined() ? UString() : message.toString(exec)->value(exec));
+        }
 
         bool appendSourceToMessage() { return m_appendSourceToMessage; }
         void setAppendSourceToMessage() { m_appendSourceToMessage = true; }
         void clearAppendSourceToMessage() { m_appendSourceToMessage = false; }
 
-        virtual bool isErrorInstance() const { return true; }
-
     protected:
-        explicit ErrorInstance(JSGlobalData*, Structure*);
-        explicit ErrorInstance(JSGlobalData*, Structure*, const UString&);
+        explicit ErrorInstance(JSGlobalData&, Structure*);
+
+        void finishCreation(JSGlobalData& globalData, const UString& message)
+        {
+            Base::finishCreation(globalData);
+            ASSERT(inherits(&s_info));
+            if (!message.isNull())
+                putDirect(globalData, globalData.propertyNames->message, jsString(&globalData, message), DontEnum);
+        }
 
         bool m_appendSourceToMessage;
     };