michael@0: /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- michael@0: * vim: set ts=8 sts=4 et sw=4 tw=99: michael@0: * This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef vm_ErrorObject_h_ michael@0: #define vm_ErrorObject_h_ michael@0: michael@0: #include "jsobj.h" michael@0: michael@0: #include "vm/Shape.h" michael@0: michael@0: struct JSExnPrivate; michael@0: michael@0: /* michael@0: * Initialize the exception constructor/prototype hierarchy. michael@0: */ michael@0: extern JSObject * michael@0: js_InitExceptionClasses(JSContext *cx, JS::HandleObject obj); michael@0: michael@0: namespace js { michael@0: michael@0: class ErrorObject : public JSObject michael@0: { michael@0: static ErrorObject * michael@0: createProto(JSContext *cx, JS::Handle global, JSExnType type, michael@0: JS::HandleObject proto); michael@0: michael@0: /* For access to createProto. */ michael@0: friend JSObject * michael@0: ::js_InitExceptionClasses(JSContext *cx, JS::HandleObject global); michael@0: michael@0: /* For access to assignInitialShape. */ michael@0: friend bool michael@0: EmptyShape::ensureInitialCustomShape(ExclusiveContext *cx, michael@0: Handle obj); michael@0: michael@0: /* michael@0: * Assign the initial error shape to the empty object. (This shape does michael@0: * *not* include .message, which must be added separately if needed; see michael@0: * ErrorObject::init.) michael@0: */ michael@0: static Shape * michael@0: assignInitialShape(ExclusiveContext *cx, Handle obj); michael@0: michael@0: static bool michael@0: init(JSContext *cx, Handle obj, JSExnType type, michael@0: ScopedJSFreePtr *errorReport, HandleString fileName, HandleString stack, michael@0: uint32_t lineNumber, uint32_t columnNumber, HandleString message); michael@0: michael@0: protected: michael@0: static const uint32_t EXNTYPE_SLOT = 0; michael@0: static const uint32_t ERROR_REPORT_SLOT = EXNTYPE_SLOT + 1; michael@0: static const uint32_t FILENAME_SLOT = ERROR_REPORT_SLOT + 1; michael@0: static const uint32_t LINENUMBER_SLOT = FILENAME_SLOT + 1; michael@0: static const uint32_t COLUMNNUMBER_SLOT = LINENUMBER_SLOT + 1; michael@0: static const uint32_t STACK_SLOT = COLUMNNUMBER_SLOT + 1; michael@0: static const uint32_t MESSAGE_SLOT = STACK_SLOT + 1; michael@0: michael@0: static const uint32_t RESERVED_SLOTS = MESSAGE_SLOT + 1; michael@0: michael@0: public: michael@0: static const Class class_; michael@0: michael@0: // Create an error of the given type corresponding to the provided location michael@0: // info. If |message| is non-null, then the error will have a .message michael@0: // property with that value; otherwise the error will have no .message michael@0: // property. michael@0: static ErrorObject * michael@0: create(JSContext *cx, JSExnType type, HandleString stack, HandleString fileName, michael@0: uint32_t lineNumber, uint32_t columnNumber, ScopedJSFreePtr *report, michael@0: HandleString message); michael@0: michael@0: JSExnType type() const { michael@0: return JSExnType(getReservedSlot(EXNTYPE_SLOT).toInt32()); michael@0: } michael@0: michael@0: JSErrorReport * getErrorReport() const { michael@0: const Value &slot = getReservedSlot(ERROR_REPORT_SLOT); michael@0: if (slot.isUndefined()) michael@0: return nullptr; michael@0: return static_cast(slot.toPrivate()); michael@0: } michael@0: michael@0: JSErrorReport * getOrCreateErrorReport(JSContext *cx); michael@0: michael@0: inline JSString * fileName(JSContext *cx) const; michael@0: inline uint32_t lineNumber() const; michael@0: inline uint32_t columnNumber() const; michael@0: inline JSString * stack(JSContext *cx) const; michael@0: michael@0: JSString * getMessage() const { michael@0: const HeapSlot &slot = getReservedSlotRef(MESSAGE_SLOT); michael@0: return slot.isString() ? slot.toString() : nullptr; michael@0: } michael@0: }; michael@0: michael@0: } // namespace js michael@0: michael@0: #endif // vm_ErrorObject_h_