Debian Codegraph @

js/src/vm/ErrorObject-inl.h

raw
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 * vim: set ts=8 sts=2 et sw=2 tw=80:
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7 #ifndef vm_ErrorObject_inl_h
8 #define vm_ErrorObject_inl_h
9
10 #include "vm/ErrorObject.h"
11
12 #include "js/ColumnNumber.h" // JS::ColumnNumberOneOrigin
13
14 #include "vm/JSAtomState.h"
15 #include "vm/JSContext.h"
16
17 inline JSString* js::ErrorObject::fileName(JSContext* cx) const {
18 Value val = getReservedSlot(FILENAME_SLOT);
19 return val.isString() ? val.toString() : cx->names().empty_;
20 }
21
22 inline uint32_t js::ErrorObject::sourceId() const {
23 Value val = getReservedSlot(SOURCEID_SLOT);
24 return val.isInt32() ? val.toInt32() : 0;
25 }
26
27 inline uint32_t js::ErrorObject::lineNumber() const {
28 Value val = getReservedSlot(LINENUMBER_SLOT);
29 return val.isInt32() ? val.toInt32() : 0;
30 }
31
32 inline JS::ColumnNumberOneOrigin js::ErrorObject::columnNumber() const {
33 Value val = getReservedSlot(COLUMNNUMBER_SLOT);
34 // If Error object's `columnNumber` property is modified from JS code,
35 // COLUMNNUMBER_SLOT slot can contain non-int32 value.
36 // Use column number 1 as fallback value for such case.
37 return val.isInt32() ? JS::ColumnNumberOneOrigin(val.toInt32())
38 : JS::ColumnNumberOneOrigin();
39 }
40
41 inline JSObject* js::ErrorObject::stack() const {
42 // If the stack was a CCW, it might have been turned into a dead object proxy
43 // by NukeCrossCompartmentWrapper. Return nullptr in this case.
44 JSObject* obj = getReservedSlot(STACK_SLOT).toObjectOrNull();
45 if (obj && obj->canUnwrapAs<SavedFrame>()) {
46 return obj;
47 }
48 return nullptr;
49 }
50
51 #endif /* vm_ErrorObject_inl_h */