summaryrefslogtreecommitdiffstats
path: root/js/src/jsapi.h
diff options
context:
space:
mode:
Diffstat (limited to 'js/src/jsapi.h')
-rw-r--r--js/src/jsapi.h205
1 files changed, 157 insertions, 48 deletions
diff --git a/js/src/jsapi.h b/js/src/jsapi.h
index c1195cc00..dc00c650d 100644
--- a/js/src/jsapi.h
+++ b/js/src/jsapi.h
@@ -18,6 +18,7 @@
#include "mozilla/RefPtr.h"
#include "mozilla/Variant.h"
+#include <iterator>
#include <stdarg.h>
#include <stddef.h>
#include <stdint.h>
@@ -36,6 +37,7 @@
#include "js/Realm.h"
#include "js/RootingAPI.h"
#include "js/TracingAPI.h"
+#include "js/UniquePtr.h"
#include "js/Utility.h"
#include "js/Value.h"
#include "js/Vector.h"
@@ -652,6 +654,7 @@ typedef enum JSExnType {
JSEXN_WASMRUNTIMEERROR,
JSEXN_ERROR_LIMIT,
JSEXN_WARN = JSEXN_ERROR_LIMIT,
+ JSEXN_NOTE,
JSEXN_LIMIT
} JSExnType;
@@ -1093,7 +1096,6 @@ class JS_PUBLIC_API(ContextOptions) {
wasmAlwaysBaseline_(false),
throwOnAsmJSValidationFailure_(false),
nativeRegExp_(true),
- unboxedArrays_(false),
asyncStack_(true),
throwOnDebuggeeWouldRun_(true),
dumpStackOnDebuggeeWouldRun_(false),
@@ -1170,12 +1172,6 @@ class JS_PUBLIC_API(ContextOptions) {
return *this;
}
- bool unboxedArrays() const { return unboxedArrays_; }
- ContextOptions& setUnboxedArrays(bool flag) {
- unboxedArrays_ = flag;
- return *this;
- }
-
bool asyncStack() const { return asyncStack_; }
ContextOptions& setAsyncStack(bool flag) {
asyncStack_ = flag;
@@ -1238,7 +1234,6 @@ class JS_PUBLIC_API(ContextOptions) {
bool wasmAlwaysBaseline_ : 1;
bool throwOnAsmJSValidationFailure_ : 1;
bool nativeRegExp_ : 1;
- bool unboxedArrays_ : 1;
bool asyncStack_ : 1;
bool throwOnDebuggeeWouldRun_ : 1;
bool dumpStackOnDebuggeeWouldRun_ : 1;
@@ -2154,6 +2149,13 @@ namespace JS {
extern JS_PUBLIC_API(bool)
OrdinaryHasInstance(JSContext* cx, HandleObject objArg, HandleValue v, bool* bp);
+// Implementation of
+// https://www.ecma-international.org/ecma-262/6.0/#sec-instanceofoperator
+// This is almost identical to JS_HasInstance, except the latter may call a
+// custom hasInstance class op instead of InstanceofOperator.
+extern JS_PUBLIC_API(bool)
+InstanceofOperator(JSContext* cx, HandleObject obj, HandleValue v, bool* bp);
+
} // namespace JS
extern JS_PUBLIC_API(void*)
@@ -2917,9 +2919,12 @@ JS_GetOwnPropertyDescriptor(JSContext* cx, JS::HandleObject obj, const char* nam
JS::MutableHandle<JS::PropertyDescriptor> desc);
extern JS_PUBLIC_API(bool)
-JS_GetOwnUCPropertyDescriptor(JSContext* cx, JS::HandleObject obj, const char16_t* name,
+JS_GetOwnUCPropertyDescriptor(JSContext* cx, JS::HandleObject obj, const char16_t* name, size_t namelen,
JS::MutableHandle<JS::PropertyDescriptor> desc);
+extern JS_PUBLIC_API(bool)
+JS_GetOwnElement(JSContext* cx, JS::HandleObject obj, uint32_t index, JS::MutableHandleValue vp);
+
/**
* Like JS_GetOwnPropertyDescriptorById, but also searches the prototype chain
* if no own property is found directly on obj. The object on which the
@@ -2934,6 +2939,10 @@ extern JS_PUBLIC_API(bool)
JS_GetPropertyDescriptor(JSContext* cx, JS::HandleObject obj, const char* name,
JS::MutableHandle<JS::PropertyDescriptor> desc);
+extern JS_PUBLIC_API(bool)
+JS_GetUCPropertyDescriptor(JSContext* cx, JS::HandleObject obj, const char16_t* name, size_t namelen,
+ JS::MutableHandle<JS::PropertyDescriptor> desc);
+
/**
* Define a property on obj.
*
@@ -5359,14 +5368,130 @@ JS_ReportOutOfMemory(JSContext* cx);
extern JS_PUBLIC_API(void)
JS_ReportAllocationOverflow(JSContext* cx);
-class JSErrorReport
+/**
+ * Base class that implements parts shared by JSErrorReport and
+ * JSErrorNotes::Note.
+ */
+class JSErrorBase
{
// The (default) error message.
// If ownsMessage_ is true, the it is freed in destructor.
JS::ConstUTF8CharsZ message_;
+ public:
+ JSErrorBase()
+ : filename(nullptr), lineno(0), column(0),
+ errorNumber(0),
+ ownsMessage_(false)
+ {}
+
+ ~JSErrorBase() {
+ freeMessage();
+ }
+
+ // Source file name, URL, etc., or null.
+ const char* filename;
+
+ // Source line number.
+ unsigned lineno;
+
+ // Zero-based column index in line.
+ unsigned column;
+
+ // the error number, e.g. see js.msg.
+ unsigned errorNumber;
+
+ private:
+ bool ownsMessage_ : 1;
+
+ public:
+ const JS::ConstUTF8CharsZ message() const {
+ return message_;
+ }
+
+ void initOwnedMessage(const char* messageArg) {
+ initBorrowedMessage(messageArg);
+ ownsMessage_ = true;
+ }
+ void initBorrowedMessage(const char* messageArg) {
+ MOZ_ASSERT(!message_);
+ message_ = JS::ConstUTF8CharsZ(messageArg, strlen(messageArg));
+ }
+
+ JSString* newMessageString(JSContext* cx);
+
+ private:
+ void freeMessage();
+};
+
+/**
+ * Notes associated with JSErrorReport.
+ */
+class JSErrorNotes
+{
+ public:
+ class Note : public JSErrorBase
+ {};
+
+ private:
+ // Stores pointers to each note.
+ js::Vector<js::UniquePtr<Note>, 1, js::SystemAllocPolicy> notes_;
+
+ public:
+ JSErrorNotes();
+ ~JSErrorNotes();
+
+ // Add an note to the given position.
+ bool addNoteASCII(js::ExclusiveContext* cx,
+ const char* filename, unsigned lineno, unsigned column,
+ JSErrorCallback errorCallback, void* userRef,
+ const unsigned errorNumber, ...);
+ bool addNoteLatin1(js::ExclusiveContext* cx,
+ const char* filename, unsigned lineno, unsigned column,
+ JSErrorCallback errorCallback, void* userRef,
+ const unsigned errorNumber, ...);
+ bool addNoteUTF8(js::ExclusiveContext* cx,
+ const char* filename, unsigned lineno, unsigned column,
+ JSErrorCallback errorCallback, void* userRef,
+ const unsigned errorNumber, ...);
+
+ size_t length();
+
+ // Create a deep copy of notes.
+ js::UniquePtr<JSErrorNotes> copy(JSContext* cx);
+
+ class iterator : public std::iterator<std::input_iterator_tag, js::UniquePtr<Note>>
+ {
+ js::UniquePtr<Note>* note_;
+ public:
+ explicit iterator(js::UniquePtr<Note>* note = nullptr) : note_(note)
+ {}
+
+ bool operator==(iterator other) const {
+ return note_ == other.note_;
+ }
+ bool operator!=(iterator other) const {
+ return !(*this == other);
+ }
+ iterator& operator++() {
+ note_++;
+ return *this;
+ }
+ reference operator*() {
+ return *note_;
+ }
+ };
+ iterator begin();
+ iterator end();
+};
+
+/**
+ * Describes a single error or warning that occurs in the execution of script.
+ */
+class JSErrorReport : public JSErrorBase
+{
// Offending source line without final '\n'.
- // If ownsLinebuf__ is true, the buffer is freed in destructor.
+ // If ownsLinebuf_ is true, the buffer is freed in destructor.
const char16_t* linebuf_;
// Number of chars in linebuf_. Does not include trailing '\0'.
@@ -5378,28 +5503,29 @@ class JSErrorReport
public:
JSErrorReport()
: linebuf_(nullptr), linebufLength_(0), tokenOffset_(0),
- filename(nullptr), lineno(0), column(0),
- flags(0), errorNumber(0),
- exnType(0), isMuted(false),
- ownsLinebuf_(false), ownsMessage_(false)
+ notes(nullptr),
+ flags(0), exnType(0), isMuted(false),
+ ownsLinebuf_(false)
{}
~JSErrorReport() {
freeLinebuf();
- freeMessage();
}
- const char* filename; /* source file name, URL, etc., or null */
- unsigned lineno; /* source line number */
- unsigned column; /* zero-based column index in line */
- unsigned flags; /* error/warning, etc. */
- unsigned errorNumber; /* the error number, e.g. see js.msg */
- int16_t exnType; /* One of the JSExnType constants */
- bool isMuted : 1; /* See the comment in ReadOnlyCompileOptions. */
+ // Associated notes, or nullptr if there's no note.
+ js::UniquePtr<JSErrorNotes> notes;
+
+ // error/warning, etc.
+ unsigned flags;
+
+ // One of the JSExnType constants.
+ int16_t exnType;
+
+ // See the comment in ReadOnlyCompileOptions.
+ bool isMuted : 1;
private:
bool ownsLinebuf_ : 1;
- bool ownsMessage_ : 1;
public:
const char16_t* linebuf() const {
@@ -5411,29 +5537,16 @@ class JSErrorReport
size_t tokenOffset() const {
return tokenOffset_;
}
- void initOwnedLinebuf(const char16_t* linebufArg, size_t linebufLengthArg, size_t tokenOffsetArg) {
+ void initOwnedLinebuf(const char16_t* linebufArg, size_t linebufLengthArg,
+ size_t tokenOffsetArg) {
initBorrowedLinebuf(linebufArg, linebufLengthArg, tokenOffsetArg);
ownsLinebuf_ = true;
}
- void initBorrowedLinebuf(const char16_t* linebufArg, size_t linebufLengthArg, size_t tokenOffsetArg);
- void freeLinebuf();
-
- const JS::ConstUTF8CharsZ message() const {
- return message_;
- }
+ void initBorrowedLinebuf(const char16_t* linebufArg, size_t linebufLengthArg,
+ size_t tokenOffsetArg);
- void initOwnedMessage(const char* messageArg) {
- initBorrowedMessage(messageArg);
- ownsMessage_ = true;
- }
- void initBorrowedMessage(const char* messageArg) {
- MOZ_ASSERT(!message_);
- message_ = JS::ConstUTF8CharsZ(messageArg, strlen(messageArg));
- }
-
- JSString* newMessageString(JSContext* cx);
-
- void freeMessage();
+ private:
+ void freeLinebuf();
};
/*
@@ -6562,7 +6675,7 @@ struct JS_PUBLIC_API(PerformanceGroup) {
uint64_t refCount_;
};
-using PerformanceGroupVector = mozilla::Vector<RefPtr<js::PerformanceGroup>, 0, SystemAllocPolicy>;
+using PerformanceGroupVector = mozilla::Vector<RefPtr<js::PerformanceGroup>, 8, SystemAllocPolicy>;
/**
* Commit any Performance Monitoring data.
@@ -6601,10 +6714,6 @@ SetStopwatchIsMonitoringJank(JSContext*, bool);
extern JS_PUBLIC_API(bool)
GetStopwatchIsMonitoringJank(JSContext*);
-// Extract the CPU rescheduling data.
-extern JS_PUBLIC_API(void)
-GetPerfMonitoringTestCpuRescheduling(JSContext*, uint64_t* stayed, uint64_t* moved);
-
/**
* Add a number of microseconds to the time spent waiting on CPOWs