mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-13 05:15:45 +00:00
Bug 969382. r=jorendorff
This commit is contained in:
parent
5292d9035a
commit
44a55c3b64
@ -32,6 +32,8 @@
|
||||
|
||||
#include "jsobjinlines.h"
|
||||
|
||||
#include "vm/ErrorObject-inl.h"
|
||||
|
||||
using namespace js;
|
||||
using namespace js::gc;
|
||||
using namespace js::types;
|
||||
@ -895,10 +897,10 @@ js_CopyErrorObject(JSContext *cx, Handle<ErrorObject*> err, HandleObject scope)
|
||||
RootedString message(cx, err->getMessage());
|
||||
if (message && !cx->compartment()->wrap(cx, message.address()))
|
||||
return nullptr;
|
||||
RootedString fileName(cx, err->fileName());
|
||||
RootedString fileName(cx, err->fileName(cx));
|
||||
if (!cx->compartment()->wrap(cx, fileName.address()))
|
||||
return nullptr;
|
||||
RootedString stack(cx, err->stack());
|
||||
RootedString stack(cx, err->stack(cx));
|
||||
if (!cx->compartment()->wrap(cx, stack.address()))
|
||||
return nullptr;
|
||||
uint32_t lineNumber = err->lineNumber();
|
||||
|
@ -427,6 +427,11 @@ class JSObject : public js::ObjectImpl
|
||||
return getSlot(index);
|
||||
}
|
||||
|
||||
inline const js::HeapSlot &getReservedSlotRef(uint32_t index) const {
|
||||
JS_ASSERT(index < JSSLOT_FREE(getClass()));
|
||||
return getSlotRef(index);
|
||||
}
|
||||
|
||||
inline js::HeapSlot &getReservedSlotRef(uint32_t index) {
|
||||
JS_ASSERT(index < JSSLOT_FREE(getClass()));
|
||||
return getSlotRef(index);
|
||||
|
44
js/src/vm/ErrorObject-inl.h
Normal file
44
js/src/vm/ErrorObject-inl.h
Normal file
@ -0,0 +1,44 @@
|
||||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
* vim: set ts=8 sts=4 et sw=4 tw=99:
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#ifndef vm_ErrorObject_inl_h
|
||||
#define vm_ErrorObject_inl_h
|
||||
|
||||
#include "vm/ErrorObject.h"
|
||||
|
||||
#include "jscntxt.h"
|
||||
|
||||
inline JSString *
|
||||
js::ErrorObject::fileName(JSContext *cx) const
|
||||
{
|
||||
const HeapSlot &slot = getReservedSlotRef(FILENAME_SLOT);
|
||||
return slot.isString() ? slot.toString() : cx->names().empty;
|
||||
}
|
||||
|
||||
inline uint32_t
|
||||
js::ErrorObject::lineNumber() const
|
||||
{
|
||||
const HeapSlot &slot = getReservedSlotRef(LINENUMBER_SLOT);
|
||||
return slot.isInt32() ? slot.toInt32() : 0;
|
||||
}
|
||||
|
||||
inline uint32_t
|
||||
js::ErrorObject::columnNumber() const
|
||||
{
|
||||
const HeapSlot &slot = getReservedSlotRef(COLUMNNUMBER_SLOT);
|
||||
return slot.isInt32() ? slot.toInt32() : 0;
|
||||
}
|
||||
|
||||
inline JSString *
|
||||
js::ErrorObject::stack(JSContext *cx) const
|
||||
{
|
||||
const HeapSlot &slot = getReservedSlotRef(STACK_SLOT);
|
||||
if (slot.isString())
|
||||
return slot.toString();
|
||||
return cx->names().empty;
|
||||
}
|
||||
|
||||
#endif /* vm_ErrorObject_inl_h */
|
@ -5,7 +5,7 @@
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#include "vm/ErrorObject.h"
|
||||
#include "vm/ErrorObject-inl.h"
|
||||
|
||||
#include "jsexn.h"
|
||||
|
||||
@ -125,7 +125,7 @@ js::ErrorObject::getOrCreateErrorReport(JSContext *cx)
|
||||
|
||||
// Filename.
|
||||
JSAutoByteString filenameStr;
|
||||
if (!filenameStr.encodeLatin1(cx, fileName()))
|
||||
if (!filenameStr.encodeLatin1(cx, fileName(cx)))
|
||||
return nullptr;
|
||||
report.filename = filenameStr.ptr();
|
||||
|
||||
|
@ -85,24 +85,13 @@ class ErrorObject : public JSObject
|
||||
|
||||
JSErrorReport * getOrCreateErrorReport(JSContext *cx);
|
||||
|
||||
JSString * fileName() const {
|
||||
return getReservedSlot(FILENAME_SLOT).toString();
|
||||
}
|
||||
|
||||
uint32_t lineNumber() const {
|
||||
return getReservedSlot(LINENUMBER_SLOT).toInt32();
|
||||
}
|
||||
|
||||
uint32_t columnNumber() const {
|
||||
return getReservedSlot(COLUMNNUMBER_SLOT).toInt32();
|
||||
}
|
||||
|
||||
JSString * stack() const {
|
||||
return getReservedSlot(STACK_SLOT).toString();
|
||||
}
|
||||
inline JSString * fileName(JSContext *cx) const;
|
||||
inline uint32_t lineNumber() const;
|
||||
inline uint32_t columnNumber() const;
|
||||
inline JSString * stack(JSContext *cx) const;
|
||||
|
||||
JSString * getMessage() const {
|
||||
HeapSlot &slot = const_cast<ErrorObject*>(this)->getReservedSlotRef(MESSAGE_SLOT);
|
||||
const HeapSlot &slot = getReservedSlotRef(MESSAGE_SLOT);
|
||||
return slot.isString() ? slot.toString() : nullptr;
|
||||
}
|
||||
};
|
||||
|
@ -1325,13 +1325,17 @@ class ObjectImpl : public gc::BarrieredCell<ObjectImpl>
|
||||
return slots[slot - fixed];
|
||||
}
|
||||
|
||||
HeapSlot *getSlotAddressUnchecked(uint32_t slot) {
|
||||
const HeapSlot *getSlotAddressUnchecked(uint32_t slot) const {
|
||||
uint32_t fixed = numFixedSlots();
|
||||
if (slot < fixed)
|
||||
return fixedSlots() + slot;
|
||||
return slots + (slot - fixed);
|
||||
}
|
||||
|
||||
HeapSlot *getSlotAddressUnchecked(uint32_t slot) {
|
||||
return const_cast<ObjectImpl*>(this)->getSlotAddressUnchecked(slot);
|
||||
}
|
||||
|
||||
HeapSlot *getSlotAddress(uint32_t slot) {
|
||||
/*
|
||||
* This can be used to get the address of the end of the slots for the
|
||||
@ -1342,11 +1346,26 @@ class ObjectImpl : public gc::BarrieredCell<ObjectImpl>
|
||||
return getSlotAddressUnchecked(slot);
|
||||
}
|
||||
|
||||
const HeapSlot *getSlotAddress(uint32_t slot) const {
|
||||
/*
|
||||
* This can be used to get the address of the end of the slots for the
|
||||
* object, which may be necessary when fetching zero-length arrays of
|
||||
* slots (e.g. for callObjVarArray).
|
||||
*/
|
||||
MOZ_ASSERT(slotInRange(slot, SENTINEL_ALLOWED));
|
||||
return getSlotAddressUnchecked(slot);
|
||||
}
|
||||
|
||||
HeapSlot &getSlotRef(uint32_t slot) {
|
||||
MOZ_ASSERT(slotInRange(slot));
|
||||
return *getSlotAddress(slot);
|
||||
}
|
||||
|
||||
const HeapSlot &getSlotRef(uint32_t slot) const {
|
||||
MOZ_ASSERT(slotInRange(slot));
|
||||
return *getSlotAddress(slot);
|
||||
}
|
||||
|
||||
HeapSlot &nativeGetSlotRef(uint32_t slot) {
|
||||
JS_ASSERT(isNative() && slot < slotSpan());
|
||||
return getSlotRef(slot);
|
||||
|
Loading…
Reference in New Issue
Block a user