2010-03-17 07:29:37 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
2013-04-16 20:47:10 +00:00
|
|
|
* vim: set ts=8 sts=4 et sw=4 tw=99:
|
2012-05-21 11:12:37 +00:00
|
|
|
* 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/. */
|
1998-03-28 02:44:41 +00:00
|
|
|
|
2013-02-01 22:24:37 +00:00
|
|
|
/* JavaScript API. */
|
|
|
|
|
2013-06-20 00:59:46 +00:00
|
|
|
#ifndef jsapi_h
|
|
|
|
#define jsapi_h
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-09 03:54:10 +00:00
|
|
|
|
2012-01-23 11:43:16 +00:00
|
|
|
#include "mozilla/FloatingPoint.h"
|
2013-06-23 11:21:01 +00:00
|
|
|
#include "mozilla/MemoryReporting.h"
|
2014-07-10 15:36:31 +00:00
|
|
|
#include "mozilla/Range.h"
|
2012-10-31 01:28:34 +00:00
|
|
|
#include "mozilla/RangedPtr.h"
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-09 03:54:10 +00:00
|
|
|
|
2013-04-24 06:44:36 +00:00
|
|
|
#include <stdarg.h>
|
1998-03-28 02:44:41 +00:00
|
|
|
#include <stddef.h>
|
2013-07-30 14:25:31 +00:00
|
|
|
#include <stdint.h>
|
1999-04-27 15:18:57 +00:00
|
|
|
#include <stdio.h>
|
2013-02-01 21:07:10 +00:00
|
|
|
|
|
|
|
#include "jsalloc.h"
|
1998-03-28 02:44:41 +00:00
|
|
|
#include "jspubtd.h"
|
|
|
|
|
2013-03-01 04:07:23 +00:00
|
|
|
#include "js/CallArgs.h"
|
2013-08-22 05:26:57 +00:00
|
|
|
#include "js/Class.h"
|
2013-02-01 21:07:10 +00:00
|
|
|
#include "js/HashTable.h"
|
2013-08-22 05:26:56 +00:00
|
|
|
#include "js/Id.h"
|
2014-03-07 19:50:41 +00:00
|
|
|
#include "js/Principals.h"
|
2013-03-12 21:05:57 +00:00
|
|
|
#include "js/RootingAPI.h"
|
2014-04-11 22:19:05 +00:00
|
|
|
#include "js/TracingAPI.h"
|
2013-02-01 21:07:10 +00:00
|
|
|
#include "js/Utility.h"
|
2013-02-01 22:24:37 +00:00
|
|
|
#include "js/Value.h"
|
2013-02-01 21:07:10 +00:00
|
|
|
#include "js/Vector.h"
|
2011-09-19 16:34:49 +00:00
|
|
|
|
|
|
|
/************************************************************************/
|
|
|
|
|
|
|
|
namespace JS {
|
|
|
|
|
2013-08-14 01:34:24 +00:00
|
|
|
class Latin1CharsZ;
|
|
|
|
class TwoByteChars;
|
|
|
|
|
2014-07-24 09:56:43 +00:00
|
|
|
#ifdef JS_DEBUG
|
2012-01-11 08:23:08 +00:00
|
|
|
|
|
|
|
class JS_PUBLIC_API(AutoCheckRequestDepth)
|
|
|
|
{
|
|
|
|
JSContext *cx;
|
|
|
|
public:
|
2014-06-04 22:22:10 +00:00
|
|
|
explicit AutoCheckRequestDepth(JSContext *cx);
|
|
|
|
explicit AutoCheckRequestDepth(js::ContextFriendFields *cx);
|
2012-01-11 08:23:08 +00:00
|
|
|
~AutoCheckRequestDepth();
|
|
|
|
};
|
|
|
|
|
|
|
|
# define CHECK_REQUEST(cx) \
|
|
|
|
JS::AutoCheckRequestDepth _autoCheckRequestDepth(cx)
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
# define CHECK_REQUEST(cx) \
|
|
|
|
((void) 0)
|
|
|
|
|
2014-07-24 09:56:43 +00:00
|
|
|
#endif /* JS_DEBUG */
|
2012-03-28 23:35:21 +00:00
|
|
|
|
2014-02-11 10:59:15 +00:00
|
|
|
/* AutoValueArray roots an internal fixed-size array of Values. */
|
|
|
|
template <size_t N>
|
|
|
|
class AutoValueArray : public AutoGCRooter
|
|
|
|
{
|
|
|
|
const size_t length_;
|
|
|
|
Value elements_[N];
|
|
|
|
|
|
|
|
public:
|
2014-05-26 01:46:24 +00:00
|
|
|
explicit AutoValueArray(JSContext *cx
|
|
|
|
MOZ_GUARD_OBJECT_NOTIFIER_PARAM)
|
2014-03-24 22:32:36 +00:00
|
|
|
: AutoGCRooter(cx, VALARRAY), length_(N)
|
2014-02-11 10:59:15 +00:00
|
|
|
{
|
|
|
|
/* Always initialize in case we GC before assignment. */
|
|
|
|
mozilla::PodArrayZero(elements_);
|
|
|
|
MOZ_GUARD_OBJECT_NOTIFIER_INIT;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned length() const { return length_; }
|
|
|
|
const Value *begin() const { return elements_; }
|
|
|
|
Value *begin() { return elements_; }
|
|
|
|
|
|
|
|
HandleValue operator[](unsigned i) const {
|
2014-10-01 17:17:51 +00:00
|
|
|
MOZ_ASSERT(i < N);
|
2014-02-11 10:59:15 +00:00
|
|
|
return HandleValue::fromMarkedLocation(&elements_[i]);
|
|
|
|
}
|
|
|
|
MutableHandleValue operator[](unsigned i) {
|
2014-10-01 17:17:51 +00:00
|
|
|
MOZ_ASSERT(i < N);
|
2014-02-11 10:59:15 +00:00
|
|
|
return MutableHandleValue::fromMarkedLocation(&elements_[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER
|
|
|
|
};
|
|
|
|
|
2012-01-15 08:13:11 +00:00
|
|
|
template<class T>
|
|
|
|
class AutoVectorRooter : protected AutoGCRooter
|
|
|
|
{
|
2013-10-16 06:48:20 +00:00
|
|
|
typedef js::Vector<T, 8> VectorImpl;
|
|
|
|
VectorImpl vector;
|
|
|
|
|
2012-01-15 08:13:11 +00:00
|
|
|
public:
|
|
|
|
explicit AutoVectorRooter(JSContext *cx, ptrdiff_t tag
|
2012-12-27 17:20:22 +00:00
|
|
|
MOZ_GUARD_OBJECT_NOTIFIER_PARAM)
|
2014-03-24 22:32:36 +00:00
|
|
|
: AutoGCRooter(cx, tag), vector(cx)
|
2012-01-15 08:13:11 +00:00
|
|
|
{
|
2012-12-27 17:20:22 +00:00
|
|
|
MOZ_GUARD_OBJECT_NOTIFIER_INIT;
|
2012-01-15 08:13:11 +00:00
|
|
|
}
|
|
|
|
|
2013-07-10 15:29:52 +00:00
|
|
|
explicit AutoVectorRooter(js::ContextFriendFields *cx, ptrdiff_t tag
|
|
|
|
MOZ_GUARD_OBJECT_NOTIFIER_PARAM)
|
2014-03-24 22:32:36 +00:00
|
|
|
: AutoGCRooter(cx, tag), vector(cx)
|
2013-07-10 15:29:52 +00:00
|
|
|
{
|
|
|
|
MOZ_GUARD_OBJECT_NOTIFIER_INIT;
|
|
|
|
}
|
|
|
|
|
2012-07-30 18:38:53 +00:00
|
|
|
typedef T ElementType;
|
2013-10-16 06:48:20 +00:00
|
|
|
typedef typename VectorImpl::Range Range;
|
2012-07-30 18:38:53 +00:00
|
|
|
|
2012-01-15 08:13:11 +00:00
|
|
|
size_t length() const { return vector.length(); }
|
2012-08-13 01:50:49 +00:00
|
|
|
bool empty() const { return vector.empty(); }
|
2012-01-15 08:13:11 +00:00
|
|
|
|
|
|
|
bool append(const T &v) { return vector.append(v); }
|
2015-03-12 23:09:21 +00:00
|
|
|
bool appendN(const T &v, size_t len) { return vector.appendN(v, len); }
|
2014-02-11 10:59:15 +00:00
|
|
|
bool append(const T *ptr, size_t len) { return vector.append(ptr, len); }
|
2013-07-09 23:33:29 +00:00
|
|
|
bool appendAll(const AutoVectorRooter<T> &other) {
|
|
|
|
return vector.appendAll(other.vector);
|
2012-08-10 11:55:55 +00:00
|
|
|
}
|
2012-01-15 08:13:11 +00:00
|
|
|
|
2013-04-10 18:04:24 +00:00
|
|
|
bool insert(T *p, const T &val) { return vector.insert(p, val); }
|
|
|
|
|
2012-01-15 08:13:11 +00:00
|
|
|
/* For use when space has already been reserved. */
|
|
|
|
void infallibleAppend(const T &v) { vector.infallibleAppend(v); }
|
|
|
|
|
|
|
|
void popBack() { vector.popBack(); }
|
|
|
|
T popCopy() { return vector.popCopy(); }
|
|
|
|
|
|
|
|
bool growBy(size_t inc) {
|
|
|
|
size_t oldLength = vector.length();
|
|
|
|
if (!vector.growByUninitialized(inc))
|
|
|
|
return false;
|
|
|
|
makeRangeGCSafe(oldLength);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool resize(size_t newLength) {
|
|
|
|
size_t oldLength = vector.length();
|
|
|
|
if (newLength <= oldLength) {
|
|
|
|
vector.shrinkBy(oldLength - newLength);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (!vector.growByUninitialized(newLength - oldLength))
|
|
|
|
return false;
|
|
|
|
makeRangeGCSafe(oldLength);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void clear() { vector.clear(); }
|
|
|
|
|
|
|
|
bool reserve(size_t newLength) {
|
|
|
|
return vector.reserve(newLength);
|
|
|
|
}
|
|
|
|
|
2014-04-28 14:53:00 +00:00
|
|
|
JS::MutableHandle<T> operator[](size_t i) {
|
2013-08-01 20:55:12 +00:00
|
|
|
return JS::MutableHandle<T>::fromMarkedLocation(&vector[i]);
|
|
|
|
}
|
2014-04-28 14:53:00 +00:00
|
|
|
JS::Handle<T> operator[](size_t i) const {
|
2013-08-01 20:55:12 +00:00
|
|
|
return JS::Handle<T>::fromMarkedLocation(&vector[i]);
|
|
|
|
}
|
2012-06-21 21:18:02 +00:00
|
|
|
|
2012-01-15 08:13:11 +00:00
|
|
|
const T *begin() const { return vector.begin(); }
|
|
|
|
T *begin() { return vector.begin(); }
|
|
|
|
|
|
|
|
const T *end() const { return vector.end(); }
|
|
|
|
T *end() { return vector.end(); }
|
|
|
|
|
2013-10-16 06:48:20 +00:00
|
|
|
Range all() { return vector.all(); }
|
|
|
|
|
2012-01-15 08:13:11 +00:00
|
|
|
const T &back() const { return vector.back(); }
|
|
|
|
|
|
|
|
friend void AutoGCRooter::trace(JSTracer *trc);
|
|
|
|
|
|
|
|
private:
|
|
|
|
void makeRangeGCSafe(size_t oldLength) {
|
|
|
|
T *t = vector.begin() + oldLength;
|
|
|
|
for (size_t i = oldLength; i < vector.length(); ++i, ++t)
|
|
|
|
memset(t, 0, sizeof(T));
|
|
|
|
}
|
|
|
|
|
2012-12-27 17:20:22 +00:00
|
|
|
MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER
|
2012-01-15 08:13:11 +00:00
|
|
|
};
|
|
|
|
|
2012-12-13 21:50:56 +00:00
|
|
|
template<class Key, class Value>
|
|
|
|
class AutoHashMapRooter : protected AutoGCRooter
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
typedef js::HashMap<Key, Value> HashMapImpl;
|
|
|
|
|
|
|
|
public:
|
|
|
|
explicit AutoHashMapRooter(JSContext *cx, ptrdiff_t tag
|
2012-12-27 17:20:22 +00:00
|
|
|
MOZ_GUARD_OBJECT_NOTIFIER_PARAM)
|
2012-12-13 21:50:56 +00:00
|
|
|
: AutoGCRooter(cx, tag), map(cx)
|
|
|
|
{
|
2012-12-27 17:20:22 +00:00
|
|
|
MOZ_GUARD_OBJECT_NOTIFIER_INIT;
|
2012-12-13 21:50:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
typedef Key KeyType;
|
|
|
|
typedef Value ValueType;
|
2013-10-16 06:48:20 +00:00
|
|
|
typedef typename HashMapImpl::Entry Entry;
|
2012-12-13 21:50:56 +00:00
|
|
|
typedef typename HashMapImpl::Lookup Lookup;
|
|
|
|
typedef typename HashMapImpl::Ptr Ptr;
|
|
|
|
typedef typename HashMapImpl::AddPtr AddPtr;
|
|
|
|
|
|
|
|
bool init(uint32_t len = 16) {
|
|
|
|
return map.init(len);
|
|
|
|
}
|
|
|
|
bool initialized() const {
|
|
|
|
return map.initialized();
|
|
|
|
}
|
|
|
|
Ptr lookup(const Lookup &l) const {
|
|
|
|
return map.lookup(l);
|
|
|
|
}
|
|
|
|
void remove(Ptr p) {
|
|
|
|
map.remove(p);
|
|
|
|
}
|
|
|
|
AddPtr lookupForAdd(const Lookup &l) const {
|
|
|
|
return map.lookupForAdd(l);
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename KeyInput, typename ValueInput>
|
|
|
|
bool add(AddPtr &p, const KeyInput &k, const ValueInput &v) {
|
2013-02-07 08:22:28 +00:00
|
|
|
return map.add(p, k, v);
|
2012-12-13 21:50:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool add(AddPtr &p, const Key &k) {
|
|
|
|
return map.add(p, k);
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename KeyInput, typename ValueInput>
|
|
|
|
bool relookupOrAdd(AddPtr &p, const KeyInput &k, const ValueInput &v) {
|
|
|
|
return map.relookupOrAdd(p, k, v);
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef typename HashMapImpl::Range Range;
|
|
|
|
Range all() const {
|
|
|
|
return map.all();
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef typename HashMapImpl::Enum Enum;
|
|
|
|
|
|
|
|
void clear() {
|
|
|
|
map.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
void finish() {
|
|
|
|
map.finish();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool empty() const {
|
|
|
|
return map.empty();
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t count() const {
|
|
|
|
return map.count();
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t capacity() const {
|
|
|
|
return map.capacity();
|
|
|
|
}
|
|
|
|
|
2013-06-23 11:21:01 +00:00
|
|
|
size_t sizeOfExcludingThis(mozilla::MallocSizeOf mallocSizeOf) const {
|
2012-12-13 21:50:56 +00:00
|
|
|
return map.sizeOfExcludingThis(mallocSizeOf);
|
|
|
|
}
|
2013-06-23 11:21:01 +00:00
|
|
|
size_t sizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf) const {
|
2012-12-13 21:50:56 +00:00
|
|
|
return map.sizeOfIncludingThis(mallocSizeOf);
|
|
|
|
}
|
|
|
|
|
2014-07-16 23:51:09 +00:00
|
|
|
uint32_t generation() const {
|
2012-12-13 21:50:56 +00:00
|
|
|
return map.generation();
|
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************** Shorthand operations */
|
|
|
|
|
|
|
|
bool has(const Lookup &l) const {
|
|
|
|
return map.has(l);
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename KeyInput, typename ValueInput>
|
|
|
|
bool put(const KeyInput &k, const ValueInput &v) {
|
|
|
|
return map.put(k, v);
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename KeyInput, typename ValueInput>
|
|
|
|
bool putNew(const KeyInput &k, const ValueInput &v) {
|
|
|
|
return map.putNew(k, v);
|
|
|
|
}
|
|
|
|
|
|
|
|
Ptr lookupWithDefault(const Key &k, const Value &defaultValue) {
|
|
|
|
return map.lookupWithDefault(k, defaultValue);
|
|
|
|
}
|
|
|
|
|
|
|
|
void remove(const Lookup &l) {
|
|
|
|
map.remove(l);
|
|
|
|
}
|
|
|
|
|
|
|
|
friend void AutoGCRooter::trace(JSTracer *trc);
|
|
|
|
|
|
|
|
private:
|
2015-01-06 23:35:02 +00:00
|
|
|
AutoHashMapRooter(const AutoHashMapRooter &hmr) = delete;
|
|
|
|
AutoHashMapRooter &operator=(const AutoHashMapRooter &hmr) = delete;
|
2012-12-13 21:50:56 +00:00
|
|
|
|
|
|
|
HashMapImpl map;
|
|
|
|
|
2012-12-27 17:20:22 +00:00
|
|
|
MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER
|
2012-12-13 21:50:56 +00:00
|
|
|
};
|
|
|
|
|
2013-02-07 08:22:28 +00:00
|
|
|
template<class T>
|
|
|
|
class AutoHashSetRooter : protected AutoGCRooter
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
typedef js::HashSet<T> HashSetImpl;
|
|
|
|
|
|
|
|
public:
|
|
|
|
explicit AutoHashSetRooter(JSContext *cx, ptrdiff_t tag
|
|
|
|
MOZ_GUARD_OBJECT_NOTIFIER_PARAM)
|
|
|
|
: AutoGCRooter(cx, tag), set(cx)
|
|
|
|
{
|
|
|
|
MOZ_GUARD_OBJECT_NOTIFIER_INIT;
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef typename HashSetImpl::Lookup Lookup;
|
|
|
|
typedef typename HashSetImpl::Ptr Ptr;
|
|
|
|
typedef typename HashSetImpl::AddPtr AddPtr;
|
|
|
|
|
|
|
|
bool init(uint32_t len = 16) {
|
|
|
|
return set.init(len);
|
|
|
|
}
|
|
|
|
bool initialized() const {
|
|
|
|
return set.initialized();
|
|
|
|
}
|
|
|
|
Ptr lookup(const Lookup &l) const {
|
|
|
|
return set.lookup(l);
|
|
|
|
}
|
|
|
|
void remove(Ptr p) {
|
|
|
|
set.remove(p);
|
|
|
|
}
|
|
|
|
AddPtr lookupForAdd(const Lookup &l) const {
|
|
|
|
return set.lookupForAdd(l);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool add(AddPtr &p, const T &t) {
|
|
|
|
return set.add(p, t);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool relookupOrAdd(AddPtr &p, const Lookup &l, const T &t) {
|
|
|
|
return set.relookupOrAdd(p, l, t);
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef typename HashSetImpl::Range Range;
|
|
|
|
Range all() const {
|
|
|
|
return set.all();
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef typename HashSetImpl::Enum Enum;
|
|
|
|
|
|
|
|
void clear() {
|
|
|
|
set.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
void finish() {
|
|
|
|
set.finish();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool empty() const {
|
|
|
|
return set.empty();
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t count() const {
|
|
|
|
return set.count();
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t capacity() const {
|
|
|
|
return set.capacity();
|
|
|
|
}
|
|
|
|
|
2013-06-23 11:21:01 +00:00
|
|
|
size_t sizeOfExcludingThis(mozilla::MallocSizeOf mallocSizeOf) const {
|
2013-02-07 08:22:28 +00:00
|
|
|
return set.sizeOfExcludingThis(mallocSizeOf);
|
|
|
|
}
|
2013-06-23 11:21:01 +00:00
|
|
|
size_t sizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf) const {
|
2013-02-07 08:22:28 +00:00
|
|
|
return set.sizeOfIncludingThis(mallocSizeOf);
|
|
|
|
}
|
|
|
|
|
2014-07-16 23:51:09 +00:00
|
|
|
uint32_t generation() const {
|
2013-02-07 08:22:28 +00:00
|
|
|
return set.generation();
|
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************** Shorthand operations */
|
|
|
|
|
|
|
|
bool has(const Lookup &l) const {
|
|
|
|
return set.has(l);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool put(const T &t) {
|
|
|
|
return set.put(t);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool putNew(const T &t) {
|
|
|
|
return set.putNew(t);
|
|
|
|
}
|
|
|
|
|
|
|
|
void remove(const Lookup &l) {
|
|
|
|
set.remove(l);
|
|
|
|
}
|
|
|
|
|
|
|
|
friend void AutoGCRooter::trace(JSTracer *trc);
|
|
|
|
|
|
|
|
private:
|
2015-01-06 23:35:02 +00:00
|
|
|
AutoHashSetRooter(const AutoHashSetRooter &hmr) = delete;
|
|
|
|
AutoHashSetRooter &operator=(const AutoHashSetRooter &hmr) = delete;
|
2013-02-07 08:22:28 +00:00
|
|
|
|
|
|
|
HashSetImpl set;
|
|
|
|
|
|
|
|
MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER
|
|
|
|
};
|
|
|
|
|
2013-09-20 22:04:53 +00:00
|
|
|
class MOZ_STACK_CLASS AutoValueVector : public AutoVectorRooter<Value>
|
2012-01-15 08:13:11 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
explicit AutoValueVector(JSContext *cx
|
2012-12-27 17:20:22 +00:00
|
|
|
MOZ_GUARD_OBJECT_NOTIFIER_PARAM)
|
2012-01-15 08:13:11 +00:00
|
|
|
: AutoVectorRooter<Value>(cx, VALVECTOR)
|
|
|
|
{
|
2012-12-27 17:20:22 +00:00
|
|
|
MOZ_GUARD_OBJECT_NOTIFIER_INIT;
|
2012-01-15 08:13:11 +00:00
|
|
|
}
|
|
|
|
|
2012-12-27 17:20:22 +00:00
|
|
|
MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER
|
2012-01-15 08:13:11 +00:00
|
|
|
};
|
|
|
|
|
2012-01-15 08:13:11 +00:00
|
|
|
class AutoIdVector : public AutoVectorRooter<jsid>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
explicit AutoIdVector(JSContext *cx
|
2012-12-27 17:20:22 +00:00
|
|
|
MOZ_GUARD_OBJECT_NOTIFIER_PARAM)
|
2012-01-15 08:13:11 +00:00
|
|
|
: AutoVectorRooter<jsid>(cx, IDVECTOR)
|
|
|
|
{
|
2012-12-27 17:20:22 +00:00
|
|
|
MOZ_GUARD_OBJECT_NOTIFIER_INIT;
|
2012-01-15 08:13:11 +00:00
|
|
|
}
|
|
|
|
|
2012-12-27 17:20:22 +00:00
|
|
|
MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER
|
2012-01-15 08:13:11 +00:00
|
|
|
};
|
|
|
|
|
2013-05-03 20:53:07 +00:00
|
|
|
class AutoObjectVector : public AutoVectorRooter<JSObject *>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
explicit AutoObjectVector(JSContext *cx
|
|
|
|
MOZ_GUARD_OBJECT_NOTIFIER_PARAM)
|
|
|
|
: AutoVectorRooter<JSObject *>(cx, OBJVECTOR)
|
|
|
|
{
|
|
|
|
MOZ_GUARD_OBJECT_NOTIFIER_INIT;
|
|
|
|
}
|
|
|
|
|
|
|
|
MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER
|
|
|
|
};
|
|
|
|
|
2013-06-14 20:48:39 +00:00
|
|
|
class AutoFunctionVector : public AutoVectorRooter<JSFunction *>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
explicit AutoFunctionVector(JSContext *cx
|
2013-07-10 15:29:52 +00:00
|
|
|
MOZ_GUARD_OBJECT_NOTIFIER_PARAM)
|
|
|
|
: AutoVectorRooter<JSFunction *>(cx, FUNVECTOR)
|
|
|
|
{
|
|
|
|
MOZ_GUARD_OBJECT_NOTIFIER_INIT;
|
|
|
|
}
|
|
|
|
|
|
|
|
explicit AutoFunctionVector(js::ContextFriendFields *cx
|
|
|
|
MOZ_GUARD_OBJECT_NOTIFIER_PARAM)
|
2013-06-14 20:48:39 +00:00
|
|
|
: AutoVectorRooter<JSFunction *>(cx, FUNVECTOR)
|
|
|
|
{
|
|
|
|
MOZ_GUARD_OBJECT_NOTIFIER_INIT;
|
|
|
|
}
|
|
|
|
|
|
|
|
MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER
|
|
|
|
};
|
|
|
|
|
2012-03-03 01:19:56 +00:00
|
|
|
class AutoScriptVector : public AutoVectorRooter<JSScript *>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
explicit AutoScriptVector(JSContext *cx
|
2012-12-27 17:20:22 +00:00
|
|
|
MOZ_GUARD_OBJECT_NOTIFIER_PARAM)
|
2012-03-03 01:19:56 +00:00
|
|
|
: AutoVectorRooter<JSScript *>(cx, SCRIPTVECTOR)
|
|
|
|
{
|
2012-12-27 17:20:22 +00:00
|
|
|
MOZ_GUARD_OBJECT_NOTIFIER_INIT;
|
2012-03-03 01:19:56 +00:00
|
|
|
}
|
|
|
|
|
2012-12-27 17:20:22 +00:00
|
|
|
MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER
|
2012-03-03 01:19:56 +00:00
|
|
|
};
|
|
|
|
|
2013-04-04 09:39:05 +00:00
|
|
|
/*
|
2014-05-21 18:31:02 +00:00
|
|
|
* Custom rooting behavior for internal and external clients.
|
2013-04-04 09:39:05 +00:00
|
|
|
*/
|
|
|
|
class JS_PUBLIC_API(CustomAutoRooter) : private AutoGCRooter
|
|
|
|
{
|
|
|
|
public:
|
2013-07-10 15:29:52 +00:00
|
|
|
template <typename CX>
|
|
|
|
explicit CustomAutoRooter(CX *cx MOZ_GUARD_OBJECT_NOTIFIER_PARAM)
|
2013-04-04 09:39:05 +00:00
|
|
|
: AutoGCRooter(cx, CUSTOM)
|
|
|
|
{
|
|
|
|
MOZ_GUARD_OBJECT_NOTIFIER_INIT;
|
|
|
|
}
|
|
|
|
|
|
|
|
friend void AutoGCRooter::trace(JSTracer *trc);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
/* Supplied by derived class to trace roots. */
|
|
|
|
virtual void trace(JSTracer *trc) = 0;
|
|
|
|
|
|
|
|
private:
|
|
|
|
MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER
|
|
|
|
};
|
|
|
|
|
2014-06-05 14:38:00 +00:00
|
|
|
/*
|
|
|
|
* RootedGeneric<T> allows a class to instantiate its own Rooted type by
|
|
|
|
* including the method:
|
|
|
|
*
|
|
|
|
* void trace(JSTracer *trc);
|
|
|
|
*
|
|
|
|
* The trace() method must trace all of the class's fields.
|
|
|
|
*/
|
|
|
|
template <class T>
|
|
|
|
class RootedGeneric : private CustomAutoRooter
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
template <typename CX>
|
|
|
|
explicit RootedGeneric(CX *cx MOZ_GUARD_OBJECT_NOTIFIER_PARAM)
|
|
|
|
: CustomAutoRooter(cx)
|
|
|
|
{
|
|
|
|
MOZ_GUARD_OBJECT_NOTIFIER_INIT;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename CX>
|
|
|
|
explicit RootedGeneric(CX *cx, const T& initial MOZ_GUARD_OBJECT_NOTIFIER_PARAM)
|
|
|
|
: CustomAutoRooter(cx), value(initial)
|
|
|
|
{
|
|
|
|
MOZ_GUARD_OBJECT_NOTIFIER_INIT;
|
|
|
|
}
|
|
|
|
|
|
|
|
operator const T&() const { return value; }
|
|
|
|
T operator->() const { return value; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
virtual void trace(JSTracer *trc) { value->trace(trc); }
|
|
|
|
|
|
|
|
T value;
|
|
|
|
|
|
|
|
MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER
|
|
|
|
};
|
|
|
|
|
2014-02-11 10:59:16 +00:00
|
|
|
/* A handle to an array of rooted values. */
|
|
|
|
class HandleValueArray
|
|
|
|
{
|
|
|
|
const size_t length_;
|
2014-02-13 07:38:36 +00:00
|
|
|
const Value * const elements_;
|
2014-02-11 10:59:16 +00:00
|
|
|
|
|
|
|
HandleValueArray(size_t len, const Value *elements) : length_(len), elements_(elements) {}
|
|
|
|
|
|
|
|
public:
|
2014-05-26 01:46:24 +00:00
|
|
|
explicit HandleValueArray(const RootedValue& value) : length_(1), elements_(value.address()) {}
|
2014-02-11 10:59:16 +00:00
|
|
|
|
2014-05-26 01:46:24 +00:00
|
|
|
MOZ_IMPLICIT HandleValueArray(const AutoValueVector& values)
|
2014-02-11 10:59:16 +00:00
|
|
|
: length_(values.length()), elements_(values.begin()) {}
|
|
|
|
|
|
|
|
template <size_t N>
|
|
|
|
HandleValueArray(const AutoValueArray<N>& values) : length_(N), elements_(values.begin()) {}
|
|
|
|
|
|
|
|
/* CallArgs must already be rooted somewhere up the stack. */
|
2014-05-26 01:46:24 +00:00
|
|
|
MOZ_IMPLICIT HandleValueArray(const JS::CallArgs& args) : length_(args.length()), elements_(args.array()) {}
|
2014-02-11 10:59:16 +00:00
|
|
|
|
|
|
|
/* Use with care! Only call this if the data is guaranteed to be marked. */
|
|
|
|
static HandleValueArray fromMarkedLocation(size_t len, const Value *elements) {
|
|
|
|
return HandleValueArray(len, elements);
|
|
|
|
}
|
|
|
|
|
2014-02-12 10:50:46 +00:00
|
|
|
static HandleValueArray subarray(const HandleValueArray& values, size_t startIndex, size_t len) {
|
2014-10-01 17:17:51 +00:00
|
|
|
MOZ_ASSERT(startIndex + len <= values.length());
|
2014-02-11 10:59:16 +00:00
|
|
|
return HandleValueArray(len, values.begin() + startIndex);
|
|
|
|
}
|
|
|
|
|
2014-02-13 07:38:36 +00:00
|
|
|
static HandleValueArray empty() {
|
|
|
|
return HandleValueArray(0, nullptr);
|
|
|
|
}
|
|
|
|
|
2014-02-11 10:59:16 +00:00
|
|
|
size_t length() const { return length_; }
|
|
|
|
const Value *begin() const { return elements_; }
|
|
|
|
|
|
|
|
HandleValue operator[](size_t i) const {
|
2014-10-01 17:17:51 +00:00
|
|
|
MOZ_ASSERT(i < length_);
|
2014-02-11 10:59:16 +00:00
|
|
|
return HandleValue::fromMarkedLocation(&elements_[i]);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2011-09-19 16:34:49 +00:00
|
|
|
} /* namespace JS */
|
|
|
|
|
|
|
|
/************************************************************************/
|
|
|
|
|
2012-03-19 14:34:55 +00:00
|
|
|
struct JSFreeOp {
|
|
|
|
private:
|
|
|
|
JSRuntime *runtime_;
|
|
|
|
|
|
|
|
protected:
|
2014-05-26 01:46:24 +00:00
|
|
|
explicit JSFreeOp(JSRuntime *rt)
|
2012-03-19 14:34:58 +00:00
|
|
|
: runtime_(rt) { }
|
2012-03-19 14:34:55 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
JSRuntime *runtime() const {
|
|
|
|
return runtime_;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2011-09-19 16:34:49 +00:00
|
|
|
/* Callbacks and their arguments. */
|
|
|
|
|
2013-08-22 05:26:57 +00:00
|
|
|
/************************************************************************/
|
|
|
|
|
2011-09-19 16:34:49 +00:00
|
|
|
typedef enum JSContextOp {
|
|
|
|
JSCONTEXT_NEW,
|
|
|
|
JSCONTEXT_DESTROY
|
|
|
|
} JSContextOp;
|
1998-03-28 02:44:41 +00:00
|
|
|
|
2010-06-30 22:25:47 +00:00
|
|
|
/*
|
2011-09-19 16:34:49 +00:00
|
|
|
* The possible values for contextOp when the runtime calls the callback are:
|
|
|
|
* JSCONTEXT_NEW JS_NewContext successfully created a new JSContext
|
|
|
|
* instance. The callback can initialize the instance as
|
|
|
|
* required. If the callback returns false, the instance
|
|
|
|
* will be destroyed and JS_NewContext returns null. In
|
|
|
|
* this case the callback is not called again.
|
|
|
|
* JSCONTEXT_DESTROY One of JS_DestroyContext* methods is called. The
|
|
|
|
* callback may perform its own cleanup and must always
|
|
|
|
* return true.
|
|
|
|
* Any other value For future compatibility the callback must do nothing
|
|
|
|
* and return true in this case.
|
|
|
|
*/
|
2013-08-08 22:53:04 +00:00
|
|
|
typedef bool
|
2013-08-03 23:55:39 +00:00
|
|
|
(* JSContextCallback)(JSContext *cx, unsigned contextOp, void *data);
|
2011-09-19 16:34:49 +00:00
|
|
|
|
|
|
|
typedef enum JSGCStatus {
|
|
|
|
JSGC_BEGIN,
|
2012-02-29 20:23:38 +00:00
|
|
|
JSGC_END
|
2011-09-19 16:34:49 +00:00
|
|
|
} JSGCStatus;
|
|
|
|
|
2012-02-29 20:23:38 +00:00
|
|
|
typedef void
|
2013-07-09 14:28:15 +00:00
|
|
|
(* JSGCCallback)(JSRuntime *rt, JSGCStatus status, void *data);
|
2012-02-29 20:23:38 +00:00
|
|
|
|
|
|
|
typedef enum JSFinalizeStatus {
|
2012-10-12 09:45:30 +00:00
|
|
|
/*
|
|
|
|
* Called when preparing to sweep a group of compartments, before anything
|
|
|
|
* has been swept. The collector will not yield to the mutator before
|
|
|
|
* calling the callback with JSFINALIZE_GROUP_END status.
|
|
|
|
*/
|
|
|
|
JSFINALIZE_GROUP_START,
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Called when preparing to sweep a group of compartments. Weak references
|
|
|
|
* to unmarked things have been removed and things that are not swept
|
|
|
|
* incrementally have been finalized at this point. The collector may yield
|
|
|
|
* to the mutator after this point.
|
|
|
|
*/
|
|
|
|
JSFINALIZE_GROUP_END,
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Called at the end of collection when everything has been swept.
|
|
|
|
*/
|
|
|
|
JSFINALIZE_COLLECTION_END
|
2012-02-29 20:23:38 +00:00
|
|
|
} JSFinalizeStatus;
|
|
|
|
|
|
|
|
typedef void
|
2014-05-16 23:40:34 +00:00
|
|
|
(* JSFinalizeCallback)(JSFreeOp *fop, JSFinalizeStatus status, bool isCompartment, void *data);
|
2011-09-19 16:34:49 +00:00
|
|
|
|
2014-09-02 09:07:22 +00:00
|
|
|
typedef void
|
2014-09-24 11:54:11 +00:00
|
|
|
(* JSWeakPointerCallback)(JSRuntime *rt, void *data);
|
2014-09-02 09:07:22 +00:00
|
|
|
|
2013-08-08 22:53:04 +00:00
|
|
|
typedef bool
|
2014-03-10 21:28:43 +00:00
|
|
|
(* JSInterruptCallback)(JSContext *cx);
|
2011-09-19 16:34:49 +00:00
|
|
|
|
|
|
|
typedef void
|
|
|
|
(* JSErrorReporter)(JSContext *cx, const char *message, JSErrorReport *report);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Possible exception types. These types are part of a JSErrorFormatString
|
|
|
|
* structure. They define which error to throw in case of a runtime error.
|
|
|
|
* JSEXN_NONE marks an unthrowable error.
|
|
|
|
*/
|
|
|
|
typedef enum JSExnType {
|
|
|
|
JSEXN_NONE = -1,
|
|
|
|
JSEXN_ERR,
|
|
|
|
JSEXN_INTERNALERR,
|
|
|
|
JSEXN_EVALERR,
|
|
|
|
JSEXN_RANGEERR,
|
|
|
|
JSEXN_REFERENCEERR,
|
|
|
|
JSEXN_SYNTAXERR,
|
|
|
|
JSEXN_TYPEERR,
|
|
|
|
JSEXN_URIERR,
|
|
|
|
JSEXN_LIMIT
|
|
|
|
} JSExnType;
|
|
|
|
|
|
|
|
typedef struct JSErrorFormatString {
|
2012-10-29 20:55:17 +00:00
|
|
|
/* The error format string in ASCII. */
|
2011-09-19 16:34:49 +00:00
|
|
|
const char *format;
|
|
|
|
|
|
|
|
/* The number of arguments to expand in the formatted error message. */
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-09 03:54:10 +00:00
|
|
|
uint16_t argCount;
|
2011-09-19 16:34:49 +00:00
|
|
|
|
|
|
|
/* One of the JSExnType constants above. */
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-09 03:54:10 +00:00
|
|
|
int16_t exnType;
|
2011-09-19 16:34:49 +00:00
|
|
|
} JSErrorFormatString;
|
|
|
|
|
|
|
|
typedef const JSErrorFormatString *
|
2014-07-15 13:14:38 +00:00
|
|
|
(* JSErrorCallback)(void *userRef, const unsigned errorNumber);
|
2011-09-19 16:34:49 +00:00
|
|
|
|
2013-08-08 22:53:04 +00:00
|
|
|
typedef bool
|
2014-01-15 10:31:00 +00:00
|
|
|
(* JSLocaleToUpperCase)(JSContext *cx, JS::HandleString src, JS::MutableHandleValue rval);
|
2011-09-19 16:34:49 +00:00
|
|
|
|
2013-08-08 22:53:04 +00:00
|
|
|
typedef bool
|
2014-01-15 10:31:00 +00:00
|
|
|
(* JSLocaleToLowerCase)(JSContext *cx, JS::HandleString src, JS::MutableHandleValue rval);
|
2011-09-19 16:34:49 +00:00
|
|
|
|
2013-08-08 22:53:04 +00:00
|
|
|
typedef bool
|
2014-01-15 10:31:00 +00:00
|
|
|
(* JSLocaleCompare)(JSContext *cx, JS::HandleString src1, JS::HandleString src2,
|
|
|
|
JS::MutableHandleValue rval);
|
2011-09-19 16:34:49 +00:00
|
|
|
|
2013-08-08 22:53:04 +00:00
|
|
|
typedef bool
|
2014-01-15 10:31:00 +00:00
|
|
|
(* JSLocaleToUnicode)(JSContext *cx, const char *src, JS::MutableHandleValue rval);
|
2011-09-19 16:34:49 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Callback used to ask the embedding for the cross compartment wrapper handler
|
|
|
|
* that implements the desired prolicy for this kind of object in the
|
2012-09-12 00:14:24 +00:00
|
|
|
* destination compartment. |obj| is the object to be wrapped. If |existing| is
|
2013-10-07 16:42:55 +00:00
|
|
|
* non-nullptr, it will point to an existing wrapper object that should be
|
|
|
|
* re-used if possible. |existing| is guaranteed to be a cross-compartment
|
|
|
|
* wrapper with a lazily-defined prototype and the correct global. It is
|
|
|
|
* guaranteed not to wrap a function.
|
2011-09-19 16:34:49 +00:00
|
|
|
*/
|
|
|
|
typedef JSObject *
|
2015-02-26 20:58:59 +00:00
|
|
|
(* JSWrapObjectCallback)(JSContext *cx, JS::HandleObject existing, JS::HandleObject obj);
|
2011-09-19 16:34:49 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Callback used by the wrap hook to ask the embedding to prepare an object
|
|
|
|
* for wrapping in a context. This might include unwrapping other wrappers
|
|
|
|
* or even finding a more suitable object for the new compartment.
|
|
|
|
*/
|
|
|
|
typedef JSObject *
|
2014-01-15 10:31:00 +00:00
|
|
|
(* JSPreWrapCallback)(JSContext *cx, JS::HandleObject scope, JS::HandleObject obj,
|
2014-07-22 23:14:27 +00:00
|
|
|
JS::HandleObject objectPassedToWrap);
|
2011-09-19 16:34:49 +00:00
|
|
|
|
2013-11-26 13:45:54 +00:00
|
|
|
struct JSWrapObjectCallbacks
|
|
|
|
{
|
|
|
|
JSWrapObjectCallback wrap;
|
|
|
|
JSPreWrapCallback preWrap;
|
|
|
|
};
|
|
|
|
|
2012-03-20 10:22:05 +00:00
|
|
|
typedef void
|
|
|
|
(* JSDestroyCompartmentCallback)(JSFreeOp *fop, JSCompartment *compartment);
|
2011-09-19 16:34:49 +00:00
|
|
|
|
2013-09-25 20:41:25 +00:00
|
|
|
typedef void
|
|
|
|
(* JSZoneCallback)(JS::Zone *zone);
|
|
|
|
|
2012-07-26 01:25:47 +00:00
|
|
|
typedef void
|
|
|
|
(* JSCompartmentNameCallback)(JSRuntime *rt, JSCompartment *compartment,
|
|
|
|
char *buf, size_t bufsize);
|
|
|
|
|
2011-09-19 16:34:49 +00:00
|
|
|
/************************************************************************/
|
2010-06-30 22:25:47 +00:00
|
|
|
|
2014-01-25 04:14:56 +00:00
|
|
|
static MOZ_ALWAYS_INLINE jsval
|
2012-08-02 00:59:47 +00:00
|
|
|
JS_NumberValue(double d)
|
|
|
|
{
|
|
|
|
int32_t i;
|
2013-10-17 08:16:17 +00:00
|
|
|
d = JS::CanonicalizeNaN(d);
|
2014-02-27 15:23:11 +00:00
|
|
|
if (mozilla::NumberIsInt32(d, &i))
|
2012-08-02 00:59:47 +00:00
|
|
|
return INT_TO_JSVAL(i);
|
|
|
|
return DOUBLE_TO_JSVAL(d);
|
|
|
|
}
|
|
|
|
|
2010-06-17 01:21:34 +00:00
|
|
|
/************************************************************************/
|
|
|
|
|
2013-08-08 22:53:04 +00:00
|
|
|
JS_PUBLIC_API(bool)
|
2011-05-17 19:15:12 +00:00
|
|
|
JS_StringHasBeenInterned(JSContext *cx, JSString *str);
|
2010-06-18 06:51:54 +00:00
|
|
|
|
2012-01-11 08:23:09 +00:00
|
|
|
namespace JS {
|
|
|
|
|
2014-04-25 14:11:56 +00:00
|
|
|
// Container class for passing in script source buffers to the JS engine. This
|
|
|
|
// not only groups the buffer and length values, it also provides a way to
|
|
|
|
// optionally pass ownership of the buffer to the JS engine without copying.
|
|
|
|
// Rules for use:
|
|
|
|
//
|
|
|
|
// 1) The data array must be allocated with js_malloc() or js_realloc() if
|
|
|
|
// ownership is being granted to the SourceBufferHolder.
|
|
|
|
// 2) If ownership is not given to the SourceBufferHolder, then the memory
|
|
|
|
// must be kept alive until the JS compilation is complete.
|
|
|
|
// 3) Any code calling SourceBufferHolder::take() must guarantee to keep the
|
|
|
|
// memory alive until JS compilation completes. Normally only the JS
|
|
|
|
// engine should be calling take().
|
|
|
|
//
|
|
|
|
// Example use:
|
|
|
|
//
|
|
|
|
// size_t length = 512;
|
2014-07-22 04:43:21 +00:00
|
|
|
// char16_t* chars = static_cast<char16_t*>(js_malloc(sizeof(char16_t) * length));
|
2014-04-25 14:11:56 +00:00
|
|
|
// JS::SourceBufferHolder srcBuf(chars, length, JS::SourceBufferHolder::GiveOwnership);
|
2015-03-19 14:13:34 +00:00
|
|
|
// JS::Compile(cx, options, srcBuf);
|
2014-04-25 14:11:56 +00:00
|
|
|
//
|
|
|
|
class MOZ_STACK_CLASS SourceBufferHolder MOZ_FINAL
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
enum Ownership {
|
|
|
|
NoOwnership,
|
|
|
|
GiveOwnership
|
|
|
|
};
|
|
|
|
|
2014-07-22 04:43:21 +00:00
|
|
|
SourceBufferHolder(const char16_t *data, size_t dataLength, Ownership ownership)
|
2014-04-25 14:11:56 +00:00
|
|
|
: data_(data),
|
|
|
|
length_(dataLength),
|
|
|
|
ownsChars_(ownership == GiveOwnership)
|
|
|
|
{
|
|
|
|
// Ensure that null buffers properly return an unowned, empty,
|
|
|
|
// null-terminated string.
|
2014-07-22 04:43:21 +00:00
|
|
|
static const char16_t NullChar_ = 0;
|
2014-04-25 14:11:56 +00:00
|
|
|
if (!get()) {
|
|
|
|
data_ = &NullChar_;
|
|
|
|
length_ = 0;
|
|
|
|
ownsChars_ = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
~SourceBufferHolder() {
|
|
|
|
if (ownsChars_)
|
2014-07-22 04:43:21 +00:00
|
|
|
js_free(const_cast<char16_t *>(data_));
|
2014-04-25 14:11:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Access the underlying source buffer without affecting ownership.
|
2014-07-22 04:43:21 +00:00
|
|
|
const char16_t *get() const { return data_; }
|
2014-04-25 14:11:56 +00:00
|
|
|
|
2014-07-22 04:43:21 +00:00
|
|
|
// Length of the source buffer in char16_t code units (not bytes)
|
2014-04-25 14:11:56 +00:00
|
|
|
size_t length() const { return length_; }
|
|
|
|
|
|
|
|
// Returns true if the SourceBufferHolder owns the buffer and will free
|
|
|
|
// it upon destruction. If true, it is legal to call take().
|
|
|
|
bool ownsChars() const { return ownsChars_; }
|
|
|
|
|
|
|
|
// Retrieve and take ownership of the underlying data buffer. The caller
|
|
|
|
// is now responsible for calling js_free() on the returned value, *but only
|
|
|
|
// after JS script compilation has completed*.
|
|
|
|
//
|
|
|
|
// After the buffer has been taken the SourceBufferHolder functions as if
|
|
|
|
// it had been constructed on an unowned buffer; get() and length() still
|
|
|
|
// work. In order for this to be safe the taken buffer must be kept alive
|
|
|
|
// until after JS script compilation completes as noted above.
|
|
|
|
//
|
|
|
|
// Note, it's the caller's responsibility to check ownsChars() before taking
|
|
|
|
// the buffer. Taking and then free'ing an unowned buffer will have dire
|
|
|
|
// consequences.
|
2014-07-22 04:43:21 +00:00
|
|
|
char16_t *take() {
|
2014-10-01 17:17:51 +00:00
|
|
|
MOZ_ASSERT(ownsChars_);
|
2014-04-25 14:11:56 +00:00
|
|
|
ownsChars_ = false;
|
2014-07-22 04:43:21 +00:00
|
|
|
return const_cast<char16_t *>(data_);
|
2014-04-25 14:11:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2015-01-06 23:35:02 +00:00
|
|
|
SourceBufferHolder(SourceBufferHolder &) = delete;
|
|
|
|
SourceBufferHolder &operator=(SourceBufferHolder &) = delete;
|
2014-04-25 14:11:56 +00:00
|
|
|
|
2014-07-22 04:43:21 +00:00
|
|
|
const char16_t *data_;
|
2014-04-25 14:11:56 +00:00
|
|
|
size_t length_;
|
|
|
|
bool ownsChars_;
|
|
|
|
};
|
|
|
|
|
2012-01-11 08:23:09 +00:00
|
|
|
} /* namespace JS */
|
|
|
|
|
2010-06-17 01:21:34 +00:00
|
|
|
/************************************************************************/
|
|
|
|
|
2014-08-19 23:14:08 +00:00
|
|
|
/* Property attributes, set in JSPropertySpec and passed to API functions.
|
|
|
|
*
|
|
|
|
* NB: The data structure in which some of these values are stored only uses
|
|
|
|
* a uint8_t to store the relevant information. Proceed with caution if
|
|
|
|
* trying to reorder or change the the first byte worth of flags.
|
|
|
|
*/
|
1998-03-28 02:44:41 +00:00
|
|
|
#define JSPROP_ENUMERATE 0x01 /* property is visible to for/in loop */
|
2011-12-15 19:40:57 +00:00
|
|
|
#define JSPROP_READONLY 0x02 /* not settable: assignment is no-op.
|
|
|
|
This flag is only valid when neither
|
|
|
|
JSPROP_GETTER nor JSPROP_SETTER is
|
|
|
|
set. */
|
1998-03-28 02:44:41 +00:00
|
|
|
#define JSPROP_PERMANENT 0x04 /* property cannot be deleted */
|
2014-10-29 19:06:31 +00:00
|
|
|
#define JSPROP_PROPOP_ACCESSORS 0x08 /* Passed to JS_Define(UC)Property* and
|
|
|
|
JS_DefineElement if getters/setters
|
2015-01-30 19:56:15 +00:00
|
|
|
are JSGetterOp/JSSetterOp */
|
1999-09-21 00:13:48 +00:00
|
|
|
#define JSPROP_GETTER 0x10 /* property holds getter function */
|
|
|
|
#define JSPROP_SETTER 0x20 /* property holds setter function */
|
2000-12-05 21:47:23 +00:00
|
|
|
#define JSPROP_SHARED 0x40 /* don't allocate a value slot for this
|
|
|
|
property; don't copy the property on
|
|
|
|
set of the same-named property in an
|
|
|
|
object that delegates to a prototype
|
|
|
|
containing this property */
|
2012-03-02 02:54:01 +00:00
|
|
|
#define JSPROP_INDEX 0x80 /* name is actually (int) index */
|
2014-12-11 18:31:10 +00:00
|
|
|
#define JSPROP_DEFINE_LATE 0x100 /* Don't define property when initially creating
|
|
|
|
the constructor. Some objects like Function/Object
|
|
|
|
have self-hosted functions that can only be defined
|
|
|
|
after the initialization is already finished. */
|
2012-11-02 04:35:09 +00:00
|
|
|
#define JSFUN_STUB_GSOPS 0x200 /* use JS_PropertyStub getter/setter
|
2008-02-07 23:18:45 +00:00
|
|
|
instead of defaulting to class gsops
|
|
|
|
for property holding function */
|
|
|
|
|
2012-11-02 04:35:09 +00:00
|
|
|
#define JSFUN_CONSTRUCTOR 0x400 /* native that can be called as a ctor */
|
|
|
|
|
2014-12-09 19:44:38 +00:00
|
|
|
#define JSPROP_REDEFINE_NONCONFIGURABLE 0x800 /* If set, will allow redefining a
|
|
|
|
non-configurable property, but
|
|
|
|
only on a non-DOM global. This
|
|
|
|
is a temporary hack that will
|
|
|
|
need to go away in bug
|
|
|
|
1105518 */
|
|
|
|
|
2014-08-19 23:14:08 +00:00
|
|
|
#define JSPROP_IGNORE_ENUMERATE 0x1000 /* ignore the value in JSPROP_ENUMERATE.
|
|
|
|
This flag only valid when defining over
|
|
|
|
an existing property. */
|
|
|
|
#define JSPROP_IGNORE_READONLY 0x2000 /* ignore the value in JSPROP_READONLY.
|
|
|
|
This flag only valid when defining over
|
|
|
|
an existing property. */
|
|
|
|
#define JSPROP_IGNORE_PERMANENT 0x4000 /* ignore the value in JSPROP_PERMANENT.
|
|
|
|
This flag only valid when defining over
|
|
|
|
an existing property. */
|
|
|
|
#define JSPROP_IGNORE_VALUE 0x8000 /* ignore the Value in the descriptor. Nothing was
|
|
|
|
specified when passed to Object.defineProperty
|
|
|
|
from script. */
|
2012-11-02 04:35:09 +00:00
|
|
|
|
2005-08-30 04:28:45 +00:00
|
|
|
/*
|
2012-11-02 04:35:09 +00:00
|
|
|
* Specify a generic native prototype methods, i.e., methods of a class
|
|
|
|
* prototype that are exposed as static methods taking an extra leading
|
|
|
|
* argument: the generic |this| parameter.
|
2005-08-30 04:28:45 +00:00
|
|
|
*
|
|
|
|
* If you set this flag in a JSFunctionSpec struct's flags initializer, then
|
|
|
|
* that struct must live at least as long as the native static method object
|
|
|
|
* created due to this flag by JS_DefineFunctions or JS_InitClass. Typically
|
|
|
|
* JSFunctionSpec structs are allocated in static arrays.
|
|
|
|
*/
|
2012-11-02 04:35:09 +00:00
|
|
|
#define JSFUN_GENERIC_NATIVE 0x800
|
|
|
|
|
|
|
|
#define JSFUN_FLAGS_MASK 0xe00 /* | of all the JSFUN_* flags */
|
2005-08-30 04:28:45 +00:00
|
|
|
|
2011-09-11 18:37:43 +00:00
|
|
|
/*
|
|
|
|
* The first call to JS_CallOnce by any thread in a process will call 'func'.
|
|
|
|
* Later calls to JS_CallOnce with the same JSCallOnceType object will be
|
|
|
|
* suppressed.
|
|
|
|
*
|
|
|
|
* Equivalently: each distinct JSCallOnceType object will allow one JS_CallOnce
|
|
|
|
* to invoke its JSInitCallback.
|
|
|
|
*/
|
2013-08-08 22:53:04 +00:00
|
|
|
extern JS_PUBLIC_API(bool)
|
2011-09-11 18:37:43 +00:00
|
|
|
JS_CallOnce(JSCallOnceType *once, JSInitCallback func);
|
|
|
|
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-09 03:54:10 +00:00
|
|
|
/* Microseconds since the epoch, midnight, January 1, 1970 UTC. */
|
|
|
|
extern JS_PUBLIC_API(int64_t)
|
2007-11-07 09:17:35 +00:00
|
|
|
JS_Now(void);
|
2002-02-27 09:17:21 +00:00
|
|
|
|
1998-04-24 00:31:11 +00:00
|
|
|
/* Don't want to export data, so provide accessors for non-inline jsvals. */
|
|
|
|
extern JS_PUBLIC_API(jsval)
|
1998-03-28 02:44:41 +00:00
|
|
|
JS_GetNaNValue(JSContext *cx);
|
|
|
|
|
1998-04-24 00:31:11 +00:00
|
|
|
extern JS_PUBLIC_API(jsval)
|
1998-03-28 02:44:41 +00:00
|
|
|
JS_GetNegativeInfinityValue(JSContext *cx);
|
|
|
|
|
1998-04-24 00:31:11 +00:00
|
|
|
extern JS_PUBLIC_API(jsval)
|
1998-03-28 02:44:41 +00:00
|
|
|
JS_GetPositiveInfinityValue(JSContext *cx);
|
|
|
|
|
1998-04-24 00:31:11 +00:00
|
|
|
extern JS_PUBLIC_API(jsval)
|
1998-03-28 02:44:41 +00:00
|
|
|
JS_GetEmptyStringValue(JSContext *cx);
|
|
|
|
|
2010-11-24 16:56:43 +00:00
|
|
|
extern JS_PUBLIC_API(JSString *)
|
|
|
|
JS_GetEmptyString(JSRuntime *rt);
|
|
|
|
|
2015-01-14 01:38:05 +00:00
|
|
|
struct CompartmentTimeStats {
|
|
|
|
char compartmentName[1024];
|
|
|
|
JSAddonId *addonId;
|
|
|
|
JSCompartment *compartment;
|
2015-02-27 01:55:37 +00:00
|
|
|
uint64_t time; // microseconds
|
|
|
|
uint64_t cpowTime; // microseconds
|
2015-01-14 01:38:05 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef js::Vector<CompartmentTimeStats, 0, js::SystemAllocPolicy> CompartmentStatsVector;
|
|
|
|
|
|
|
|
extern JS_PUBLIC_API(bool)
|
|
|
|
JS_GetCompartmentStats(JSRuntime *rt, CompartmentStatsVector &stats);
|
|
|
|
|
2013-08-08 22:53:04 +00:00
|
|
|
extern JS_PUBLIC_API(bool)
|
2013-09-20 09:22:59 +00:00
|
|
|
JS_ValueToObject(JSContext *cx, JS::HandleValue v, JS::MutableHandleObject objp);
|
1998-03-28 02:44:41 +00:00
|
|
|
|
1998-04-24 00:31:11 +00:00
|
|
|
extern JS_PUBLIC_API(JSFunction *)
|
2013-09-20 09:22:59 +00:00
|
|
|
JS_ValueToFunction(JSContext *cx, JS::HandleValue v);
|
1998-03-28 02:44:41 +00:00
|
|
|
|
1998-04-24 00:31:11 +00:00
|
|
|
extern JS_PUBLIC_API(JSFunction *)
|
2013-09-20 09:22:59 +00:00
|
|
|
JS_ValueToConstructor(JSContext *cx, JS::HandleValue v);
|
1998-04-24 00:31:11 +00:00
|
|
|
|
2008-11-03 22:28:36 +00:00
|
|
|
extern JS_PUBLIC_API(JSString *)
|
2014-01-15 01:19:07 +00:00
|
|
|
JS_ValueToSource(JSContext *cx, JS::Handle<JS::Value> v);
|
2008-11-03 22:28:36 +00:00
|
|
|
|
2013-08-08 22:53:04 +00:00
|
|
|
extern JS_PUBLIC_API(bool)
|
2012-03-02 02:54:01 +00:00
|
|
|
JS_DoubleIsInt32(double d, int32_t *ip);
|
2010-03-01 21:30:23 +00:00
|
|
|
|
1998-04-24 00:31:11 +00:00
|
|
|
extern JS_PUBLIC_API(JSType)
|
2014-01-15 01:19:07 +00:00
|
|
|
JS_TypeOfValue(JSContext *cx, JS::Handle<JS::Value> v);
|
1998-03-28 02:44:41 +00:00
|
|
|
|
2013-08-08 22:53:04 +00:00
|
|
|
extern JS_PUBLIC_API(bool)
|
2015-02-17 14:03:23 +00:00
|
|
|
JS_StrictlyEqual(JSContext *cx, JS::Handle<JS::Value> v1, JS::Handle<JS::Value> v2, bool *equal);
|
2009-05-15 19:51:02 +00:00
|
|
|
|
2013-08-08 22:53:04 +00:00
|
|
|
extern JS_PUBLIC_API(bool)
|
2014-01-15 01:19:07 +00:00
|
|
|
JS_LooselyEqual(JSContext *cx, JS::Handle<JS::Value> v1, JS::Handle<JS::Value> v2, bool *equal);
|
2011-03-21 17:04:43 +00:00
|
|
|
|
2013-08-08 22:53:04 +00:00
|
|
|
extern JS_PUBLIC_API(bool)
|
2015-02-17 14:03:23 +00:00
|
|
|
JS_SameValue(JSContext *cx, JS::Handle<JS::Value> v1, JS::Handle<JS::Value> v2, bool *same);
|
2009-09-09 18:51:52 +00:00
|
|
|
|
2011-03-03 03:57:44 +00:00
|
|
|
/* True iff fun is the global eval function. */
|
2013-08-08 22:53:04 +00:00
|
|
|
extern JS_PUBLIC_API(bool)
|
2011-03-03 03:57:44 +00:00
|
|
|
JS_IsBuiltinEvalFunction(JSFunction *fun);
|
|
|
|
|
|
|
|
/* True iff fun is the Function constructor. */
|
2013-08-08 22:53:04 +00:00
|
|
|
extern JS_PUBLIC_API(bool)
|
2011-03-03 03:57:44 +00:00
|
|
|
JS_IsBuiltinFunctionConstructor(JSFunction *fun);
|
|
|
|
|
1998-03-28 02:44:41 +00:00
|
|
|
/************************************************************************/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialization, locking, contexts, and memory allocation.
|
2007-02-08 19:49:35 +00:00
|
|
|
*
|
|
|
|
* It is important that the first runtime and first context be created in a
|
|
|
|
* single-threaded fashion, otherwise the behavior of the library is undefined.
|
|
|
|
* See: http://developer.mozilla.org/en/docs/Category:JSAPI_Reference
|
1998-03-28 02:44:41 +00:00
|
|
|
*/
|
|
|
|
|
2013-07-20 03:14:34 +00:00
|
|
|
/**
|
|
|
|
* Initialize SpiderMonkey, returning true only if initialization succeeded.
|
|
|
|
* Once this method has succeeded, it is safe to call JS_NewRuntime and other
|
|
|
|
* JSAPI methods.
|
|
|
|
*
|
|
|
|
* This method must be called before any other JSAPI method is used on any
|
|
|
|
* thread. Once it has been used, it is safe to call any JSAPI method, and it
|
|
|
|
* remains safe to do so until JS_ShutDown is correctly called.
|
|
|
|
*
|
|
|
|
* It is currently not possible to initialize SpiderMonkey multiple times (that
|
|
|
|
* is, calling JS_Init/JSAPI methods/JS_ShutDown in that order, then doing so
|
|
|
|
* again). This restriction may eventually be lifted.
|
|
|
|
*/
|
2013-08-08 22:53:04 +00:00
|
|
|
extern JS_PUBLIC_API(bool)
|
2013-07-20 03:14:34 +00:00
|
|
|
JS_Init(void);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Destroy free-standing resources allocated by SpiderMonkey, not associated
|
|
|
|
* with any runtime, context, or other structure.
|
|
|
|
*
|
|
|
|
* This method should be called after all other JSAPI data has been properly
|
|
|
|
* cleaned up: every new runtime must have been destroyed, every new context
|
|
|
|
* must have been destroyed, and so on. Calling this method before all other
|
|
|
|
* resources have been destroyed has undefined behavior.
|
|
|
|
*
|
|
|
|
* Failure to call this method, at present, has no adverse effects other than
|
|
|
|
* leaking memory. This may not always be the case; it's recommended that all
|
|
|
|
* embedders call this method when all other JSAPI operations have completed.
|
|
|
|
*
|
|
|
|
* It is currently not possible to initialize SpiderMonkey multiple times (that
|
|
|
|
* is, calling JS_Init/JSAPI methods/JS_ShutDown in that order, then doing so
|
|
|
|
* again). This restriction may eventually be lifted.
|
|
|
|
*/
|
|
|
|
extern JS_PUBLIC_API(void)
|
|
|
|
JS_ShutDown(void);
|
|
|
|
|
1998-04-24 00:31:11 +00:00
|
|
|
extern JS_PUBLIC_API(JSRuntime *)
|
2014-07-11 08:59:05 +00:00
|
|
|
JS_NewRuntime(uint32_t maxbytes,
|
|
|
|
uint32_t maxNurseryBytes = JS::DefaultNurseryBytes,
|
|
|
|
JSRuntime *parentRuntime = nullptr);
|
1998-03-28 02:44:41 +00:00
|
|
|
|
1998-04-24 00:31:11 +00:00
|
|
|
extern JS_PUBLIC_API(void)
|
|
|
|
JS_DestroyRuntime(JSRuntime *rt);
|
|
|
|
|
2013-07-08 03:29:14 +00:00
|
|
|
// These are equivalent to ICU's |UMemAllocFn|, |UMemReallocFn|, and
|
|
|
|
// |UMemFreeFn| types. The first argument (called |context| in the ICU docs)
|
2013-10-07 16:42:55 +00:00
|
|
|
// will always be nullptr, and should be ignored.
|
2013-07-08 03:29:14 +00:00
|
|
|
typedef void *(*JS_ICUAllocFn)(const void *, size_t size);
|
|
|
|
typedef void *(*JS_ICUReallocFn)(const void *, void *p, size_t size);
|
|
|
|
typedef void (*JS_ICUFreeFn)(const void *, void *p);
|
|
|
|
|
|
|
|
// This function can be used to track memory used by ICU.
|
|
|
|
// Do not use it unless you know what you are doing!
|
|
|
|
extern JS_PUBLIC_API(bool)
|
|
|
|
JS_SetICUMemoryFunctions(JS_ICUAllocFn allocFn, JS_ICUReallocFn reallocFn, JS_ICUFreeFn freeFn);
|
|
|
|
|
2000-05-17 06:23:03 +00:00
|
|
|
JS_PUBLIC_API(void *)
|
|
|
|
JS_GetRuntimePrivate(JSRuntime *rt);
|
|
|
|
|
2011-07-18 21:54:48 +00:00
|
|
|
extern JS_PUBLIC_API(JSRuntime *)
|
|
|
|
JS_GetRuntime(JSContext *cx);
|
|
|
|
|
2014-02-19 16:02:13 +00:00
|
|
|
extern JS_PUBLIC_API(JSRuntime *)
|
|
|
|
JS_GetParentRuntime(JSContext *cx);
|
|
|
|
|
2000-05-17 06:23:03 +00:00
|
|
|
JS_PUBLIC_API(void)
|
|
|
|
JS_SetRuntimePrivate(JSRuntime *rt, void *data);
|
|
|
|
|
1998-04-24 00:31:11 +00:00
|
|
|
extern JS_PUBLIC_API(void)
|
|
|
|
JS_BeginRequest(JSContext *cx);
|
|
|
|
|
|
|
|
extern JS_PUBLIC_API(void)
|
|
|
|
JS_EndRequest(JSContext *cx);
|
|
|
|
|
2013-09-02 04:51:02 +00:00
|
|
|
namespace js {
|
2012-04-12 16:23:51 +00:00
|
|
|
|
2013-08-20 06:43:47 +00:00
|
|
|
void
|
|
|
|
AssertHeapIsIdle(JSRuntime *rt);
|
|
|
|
|
|
|
|
void
|
|
|
|
AssertHeapIsIdle(JSContext *cx);
|
|
|
|
|
2012-09-25 01:08:22 +00:00
|
|
|
} /* namespace js */
|
2012-04-12 16:23:51 +00:00
|
|
|
|
2012-12-27 17:20:22 +00:00
|
|
|
class JSAutoRequest
|
|
|
|
{
|
2005-08-17 16:26:14 +00:00
|
|
|
public:
|
2014-05-26 01:46:24 +00:00
|
|
|
explicit JSAutoRequest(JSContext *cx
|
|
|
|
MOZ_GUARD_OBJECT_NOTIFIER_PARAM)
|
2012-12-27 17:20:22 +00:00
|
|
|
: mContext(cx)
|
|
|
|
{
|
|
|
|
MOZ_GUARD_OBJECT_NOTIFIER_INIT;
|
2005-08-17 16:26:14 +00:00
|
|
|
JS_BeginRequest(mContext);
|
|
|
|
}
|
|
|
|
~JSAutoRequest() {
|
|
|
|
JS_EndRequest(mContext);
|
|
|
|
}
|
|
|
|
|
2008-07-17 16:37:32 +00:00
|
|
|
protected:
|
|
|
|
JSContext *mContext;
|
2012-12-27 17:20:22 +00:00
|
|
|
MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER
|
2008-07-17 16:37:32 +00:00
|
|
|
|
|
|
|
#if 0
|
|
|
|
private:
|
2014-08-18 19:20:39 +00:00
|
|
|
static void *operator new(size_t) CPP_THROW_NEW { return 0; }
|
|
|
|
static void operator delete(void *, size_t) { }
|
2008-07-17 16:37:32 +00:00
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
2013-08-03 23:55:39 +00:00
|
|
|
extern JS_PUBLIC_API(void)
|
|
|
|
JS_SetContextCallback(JSRuntime *rt, JSContextCallback cxCallback, void *data);
|
2006-06-27 12:09:09 +00:00
|
|
|
|
1998-04-24 00:31:11 +00:00
|
|
|
extern JS_PUBLIC_API(JSContext *)
|
2000-03-23 23:50:29 +00:00
|
|
|
JS_NewContext(JSRuntime *rt, size_t stackChunkSize);
|
1998-03-28 02:44:41 +00:00
|
|
|
|
1998-04-24 00:31:11 +00:00
|
|
|
extern JS_PUBLIC_API(void)
|
1998-03-28 02:44:41 +00:00
|
|
|
JS_DestroyContext(JSContext *cx);
|
|
|
|
|
1999-06-23 14:18:56 +00:00
|
|
|
extern JS_PUBLIC_API(void)
|
|
|
|
JS_DestroyContextNoGC(JSContext *cx);
|
|
|
|
|
2000-02-04 02:01:49 +00:00
|
|
|
extern JS_PUBLIC_API(void *)
|
1998-04-24 00:31:11 +00:00
|
|
|
JS_GetContextPrivate(JSContext *cx);
|
|
|
|
|
1999-11-23 01:02:28 +00:00
|
|
|
extern JS_PUBLIC_API(void)
|
1998-07-31 00:07:22 +00:00
|
|
|
JS_SetContextPrivate(JSContext *cx, void *data);
|
1998-04-24 00:31:11 +00:00
|
|
|
|
2012-01-11 08:23:07 +00:00
|
|
|
extern JS_PUBLIC_API(void *)
|
|
|
|
JS_GetSecondContextPrivate(JSContext *cx);
|
|
|
|
|
|
|
|
extern JS_PUBLIC_API(void)
|
|
|
|
JS_SetSecondContextPrivate(JSContext *cx, void *data);
|
|
|
|
|
1998-04-24 00:31:11 +00:00
|
|
|
extern JS_PUBLIC_API(JSRuntime *)
|
1998-03-28 02:44:41 +00:00
|
|
|
JS_GetRuntime(JSContext *cx);
|
|
|
|
|
1998-04-24 00:31:11 +00:00
|
|
|
extern JS_PUBLIC_API(JSContext *)
|
1998-03-28 02:44:41 +00:00
|
|
|
JS_ContextIterator(JSRuntime *rt, JSContext **iterp);
|
|
|
|
|
1998-04-24 00:31:11 +00:00
|
|
|
extern JS_PUBLIC_API(JSVersion)
|
1998-03-28 02:44:41 +00:00
|
|
|
JS_GetVersion(JSContext *cx);
|
|
|
|
|
2013-06-29 15:11:19 +00:00
|
|
|
// Mutate the version on the compartment. This is generally discouraged, but
|
|
|
|
// necessary to support the version mutation in the js and xpc shell command
|
|
|
|
// set.
|
|
|
|
//
|
|
|
|
// It would be nice to put this in jsfriendapi, but the linkage requirements
|
|
|
|
// of the shells make that impossible.
|
|
|
|
JS_PUBLIC_API(void)
|
|
|
|
JS_SetVersionForCompartment(JSCompartment *compartment, JSVersion version);
|
|
|
|
|
1999-10-29 22:44:35 +00:00
|
|
|
extern JS_PUBLIC_API(const char *)
|
|
|
|
JS_VersionToString(JSVersion version);
|
|
|
|
|
|
|
|
extern JS_PUBLIC_API(JSVersion)
|
|
|
|
JS_StringToVersion(const char *string);
|
|
|
|
|
2013-10-14 11:25:47 +00:00
|
|
|
namespace JS {
|
|
|
|
|
2014-02-26 09:25:36 +00:00
|
|
|
class JS_PUBLIC_API(RuntimeOptions) {
|
|
|
|
public:
|
|
|
|
RuntimeOptions()
|
|
|
|
: baseline_(false),
|
|
|
|
ion_(false),
|
2014-05-15 23:48:21 +00:00
|
|
|
asmJS_(false),
|
2014-07-11 15:30:47 +00:00
|
|
|
nativeRegExp_(false),
|
2015-01-27 09:47:25 +00:00
|
|
|
unboxedObjects_(false),
|
2014-07-15 16:04:20 +00:00
|
|
|
werror_(false),
|
2014-07-15 16:04:20 +00:00
|
|
|
strictMode_(false),
|
2014-07-30 04:00:37 +00:00
|
|
|
extraWarnings_(false),
|
2014-07-15 16:04:20 +00:00
|
|
|
varObjFix_(false)
|
2014-02-26 09:25:36 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool baseline() const { return baseline_; }
|
|
|
|
RuntimeOptions &setBaseline(bool flag) {
|
|
|
|
baseline_ = flag;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
RuntimeOptions &toggleBaseline() {
|
|
|
|
baseline_ = !baseline_;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ion() const { return ion_; }
|
|
|
|
RuntimeOptions &setIon(bool flag) {
|
|
|
|
ion_ = flag;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
RuntimeOptions &toggleIon() {
|
|
|
|
ion_ = !ion_;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool asmJS() const { return asmJS_; }
|
|
|
|
RuntimeOptions &setAsmJS(bool flag) {
|
|
|
|
asmJS_ = flag;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
RuntimeOptions &toggleAsmJS() {
|
|
|
|
asmJS_ = !asmJS_;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2014-05-15 23:48:21 +00:00
|
|
|
bool nativeRegExp() const { return nativeRegExp_; }
|
|
|
|
RuntimeOptions &setNativeRegExp(bool flag) {
|
|
|
|
nativeRegExp_ = flag;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2015-01-27 09:47:25 +00:00
|
|
|
bool unboxedObjects() const { return unboxedObjects_; }
|
|
|
|
RuntimeOptions &setUnboxedObjects(bool flag) {
|
|
|
|
unboxedObjects_ = flag;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2014-07-11 15:30:47 +00:00
|
|
|
bool werror() const { return werror_; }
|
|
|
|
RuntimeOptions &setWerror(bool flag) {
|
|
|
|
werror_ = flag;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
RuntimeOptions &toggleWerror() {
|
|
|
|
werror_ = !werror_;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2014-07-15 16:04:20 +00:00
|
|
|
bool strictMode() const { return strictMode_; }
|
|
|
|
RuntimeOptions &setStrictMode(bool flag) {
|
|
|
|
strictMode_ = flag;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
RuntimeOptions &toggleStrictMode() {
|
|
|
|
strictMode_ = !strictMode_;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2014-07-30 04:00:37 +00:00
|
|
|
bool extraWarnings() const { return extraWarnings_; }
|
|
|
|
RuntimeOptions &setExtraWarnings(bool flag) {
|
|
|
|
extraWarnings_ = flag;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
RuntimeOptions &toggleExtraWarnings() {
|
|
|
|
extraWarnings_ = !extraWarnings_;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2014-07-15 16:04:20 +00:00
|
|
|
bool varObjFix() const { return varObjFix_; }
|
|
|
|
RuntimeOptions &setVarObjFix(bool flag) {
|
|
|
|
varObjFix_ = flag;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
RuntimeOptions &toggleVarObjFix() {
|
|
|
|
varObjFix_ = !varObjFix_;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2014-02-26 09:25:36 +00:00
|
|
|
private:
|
|
|
|
bool baseline_ : 1;
|
|
|
|
bool ion_ : 1;
|
|
|
|
bool asmJS_ : 1;
|
2014-05-15 23:48:21 +00:00
|
|
|
bool nativeRegExp_ : 1;
|
2015-01-27 09:47:25 +00:00
|
|
|
bool unboxedObjects_ : 1;
|
2014-07-11 15:30:47 +00:00
|
|
|
bool werror_ : 1;
|
2014-07-15 16:04:20 +00:00
|
|
|
bool strictMode_ : 1;
|
2014-07-30 04:00:37 +00:00
|
|
|
bool extraWarnings_ : 1;
|
2014-07-15 16:04:20 +00:00
|
|
|
bool varObjFix_ : 1;
|
2014-02-26 09:25:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
JS_PUBLIC_API(RuntimeOptions &)
|
|
|
|
RuntimeOptionsRef(JSRuntime *rt);
|
|
|
|
|
|
|
|
JS_PUBLIC_API(RuntimeOptions &)
|
|
|
|
RuntimeOptionsRef(JSContext *cx);
|
|
|
|
|
2013-10-14 11:25:47 +00:00
|
|
|
class JS_PUBLIC_API(ContextOptions) {
|
|
|
|
public:
|
|
|
|
ContextOptions()
|
2014-07-30 04:00:37 +00:00
|
|
|
: privateIsNSISupports_(false),
|
2014-12-16 10:02:37 +00:00
|
|
|
dontReportUncaught_(false),
|
|
|
|
autoJSAPIOwnsErrorReporting_(false)
|
2013-10-14 11:25:47 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool privateIsNSISupports() const { return privateIsNSISupports_; }
|
|
|
|
ContextOptions &setPrivateIsNSISupports(bool flag) {
|
|
|
|
privateIsNSISupports_ = flag;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
ContextOptions &togglePrivateIsNSISupports() {
|
|
|
|
privateIsNSISupports_ = !privateIsNSISupports_;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool dontReportUncaught() const { return dontReportUncaught_; }
|
|
|
|
ContextOptions &setDontReportUncaught(bool flag) {
|
|
|
|
dontReportUncaught_ = flag;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
ContextOptions &toggleDontReportUncaught() {
|
|
|
|
dontReportUncaught_ = !dontReportUncaught_;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2014-12-16 10:02:37 +00:00
|
|
|
bool autoJSAPIOwnsErrorReporting() const { return autoJSAPIOwnsErrorReporting_; }
|
|
|
|
ContextOptions &setAutoJSAPIOwnsErrorReporting(bool flag) {
|
|
|
|
autoJSAPIOwnsErrorReporting_ = flag;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
ContextOptions &toggleAutoJSAPIOwnsErrorReporting() {
|
|
|
|
autoJSAPIOwnsErrorReporting_ = !autoJSAPIOwnsErrorReporting_;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-10-14 11:25:47 +00:00
|
|
|
private:
|
|
|
|
bool privateIsNSISupports_ : 1;
|
|
|
|
bool dontReportUncaught_ : 1;
|
2014-12-16 10:02:37 +00:00
|
|
|
// dontReportUncaught isn't respected by all JSAPI codepaths, particularly the
|
|
|
|
// JS_ReportError* functions that eventually report the error even when dontReportUncaught is
|
|
|
|
// set, if script is not running. We want a way to indicate that the embedder will always
|
|
|
|
// handle any exceptions, and that SpiderMonkey should just leave them on the context. This is
|
|
|
|
// the way we want to do all future error handling in Gecko - stealing the exception explicitly
|
|
|
|
// from the context and handling it as per the situation. This will eventually become the
|
|
|
|
// default and these 2 flags should go away.
|
|
|
|
bool autoJSAPIOwnsErrorReporting_ : 1;
|
2013-10-14 11:25:47 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
JS_PUBLIC_API(ContextOptions &)
|
|
|
|
ContextOptionsRef(JSContext *cx);
|
|
|
|
|
|
|
|
class JS_PUBLIC_API(AutoSaveContextOptions) {
|
|
|
|
public:
|
2014-05-26 01:46:24 +00:00
|
|
|
explicit AutoSaveContextOptions(JSContext *cx)
|
2013-10-14 11:25:47 +00:00
|
|
|
: cx_(cx),
|
|
|
|
oldOptions_(ContextOptionsRef(cx_))
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
~AutoSaveContextOptions()
|
|
|
|
{
|
|
|
|
ContextOptionsRef(cx_) = oldOptions_;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
JSContext *cx_;
|
|
|
|
JS::ContextOptions oldOptions_;
|
|
|
|
};
|
|
|
|
|
|
|
|
} /* namespace JS */
|
|
|
|
|
1998-07-31 00:07:22 +00:00
|
|
|
extern JS_PUBLIC_API(const char *)
|
|
|
|
JS_GetImplementationVersion(void);
|
|
|
|
|
2012-03-20 10:22:05 +00:00
|
|
|
extern JS_PUBLIC_API(void)
|
|
|
|
JS_SetDestroyCompartmentCallback(JSRuntime *rt, JSDestroyCompartmentCallback callback);
|
2010-07-19 20:36:49 +00:00
|
|
|
|
2013-09-25 20:41:25 +00:00
|
|
|
extern JS_PUBLIC_API(void)
|
|
|
|
JS_SetDestroyZoneCallback(JSRuntime *rt, JSZoneCallback callback);
|
|
|
|
|
2013-09-25 20:41:25 +00:00
|
|
|
extern JS_PUBLIC_API(void)
|
|
|
|
JS_SetSweepZoneCallback(JSRuntime *rt, JSZoneCallback callback);
|
|
|
|
|
2012-07-26 01:25:47 +00:00
|
|
|
extern JS_PUBLIC_API(void)
|
|
|
|
JS_SetCompartmentNameCallback(JSRuntime *rt, JSCompartmentNameCallback callback);
|
|
|
|
|
2013-11-26 13:45:54 +00:00
|
|
|
extern JS_PUBLIC_API(void)
|
|
|
|
JS_SetWrapObjectCallbacks(JSRuntime *rt, const JSWrapObjectCallbacks *callbacks);
|
2010-06-24 21:45:32 +00:00
|
|
|
|
2012-02-29 12:18:16 +00:00
|
|
|
extern JS_PUBLIC_API(void)
|
|
|
|
JS_SetCompartmentPrivate(JSCompartment *compartment, void *data);
|
2010-07-19 20:36:49 +00:00
|
|
|
|
|
|
|
extern JS_PUBLIC_API(void *)
|
2012-02-29 12:18:16 +00:00
|
|
|
JS_GetCompartmentPrivate(JSCompartment *compartment);
|
2010-07-19 20:36:49 +00:00
|
|
|
|
2013-08-27 16:42:11 +00:00
|
|
|
extern JS_PUBLIC_API(void)
|
|
|
|
JS_SetZoneUserData(JS::Zone *zone, void *data);
|
|
|
|
|
|
|
|
extern JS_PUBLIC_API(void *)
|
|
|
|
JS_GetZoneUserData(JS::Zone *zone);
|
|
|
|
|
2013-08-08 22:53:04 +00:00
|
|
|
extern JS_PUBLIC_API(bool)
|
2013-10-16 00:02:23 +00:00
|
|
|
JS_WrapObject(JSContext *cx, JS::MutableHandleObject objp);
|
2010-08-23 22:14:38 +00:00
|
|
|
|
2013-08-08 22:53:04 +00:00
|
|
|
extern JS_PUBLIC_API(bool)
|
2013-10-26 16:19:05 +00:00
|
|
|
JS_WrapValue(JSContext *cx, JS::MutableHandleValue vp);
|
2010-08-23 22:14:38 +00:00
|
|
|
|
2010-09-17 21:54:40 +00:00
|
|
|
extern JS_PUBLIC_API(JSObject *)
|
2014-01-15 10:31:00 +00:00
|
|
|
JS_TransplantObject(JSContext *cx, JS::HandleObject origobj, JS::HandleObject target);
|
2010-09-17 21:54:40 +00:00
|
|
|
|
2013-08-08 22:53:04 +00:00
|
|
|
extern JS_PUBLIC_API(bool)
|
2014-01-14 20:41:22 +00:00
|
|
|
JS_RefreshCrossCompartmentWrappers(JSContext *cx, JS::Handle<JSObject*> obj);
|
2011-02-12 00:17:25 +00:00
|
|
|
|
2012-08-27 20:32:51 +00:00
|
|
|
/*
|
2013-10-07 16:42:55 +00:00
|
|
|
* At any time, a JSContext has a current (possibly-nullptr) compartment.
|
2012-08-27 20:32:51 +00:00
|
|
|
* Compartments are described in:
|
|
|
|
*
|
|
|
|
* developer.mozilla.org/en-US/docs/SpiderMonkey/SpiderMonkey_compartments
|
|
|
|
*
|
|
|
|
* The current compartment of a context may be changed. The preferred way to do
|
|
|
|
* this is with JSAutoCompartment:
|
|
|
|
*
|
|
|
|
* void foo(JSContext *cx, JSObject *obj) {
|
|
|
|
* // in some compartment 'c'
|
|
|
|
* {
|
|
|
|
* JSAutoCompartment ac(cx, obj); // constructor enters
|
|
|
|
* // in the compartment of 'obj'
|
|
|
|
* } // destructor leaves
|
|
|
|
* // back in compartment 'c'
|
|
|
|
* }
|
|
|
|
*
|
|
|
|
* For more complicated uses that don't neatly fit in a C++ stack frame, the
|
|
|
|
* compartment can entered and left using separate function calls:
|
|
|
|
*
|
|
|
|
* void foo(JSContext *cx, JSObject *obj) {
|
|
|
|
* // in 'oldCompartment'
|
|
|
|
* JSCompartment *oldCompartment = JS_EnterCompartment(cx, obj);
|
|
|
|
* // in the compartment of 'obj'
|
|
|
|
* JS_LeaveCompartment(cx, oldCompartment);
|
|
|
|
* // back in 'oldCompartment'
|
|
|
|
* }
|
|
|
|
*
|
|
|
|
* Note: these calls must still execute in a LIFO manner w.r.t all other
|
|
|
|
* enter/leave calls on the context. Furthermore, only the return value of a
|
|
|
|
* JS_EnterCompartment call may be passed as the 'oldCompartment' argument of
|
|
|
|
* the corresponding JS_LeaveCompartment call.
|
|
|
|
*/
|
|
|
|
|
2012-08-22 01:42:53 +00:00
|
|
|
class JS_PUBLIC_API(JSAutoCompartment)
|
2010-06-24 21:44:18 +00:00
|
|
|
{
|
2012-08-18 01:05:06 +00:00
|
|
|
JSContext *cx_;
|
|
|
|
JSCompartment *oldCompartment_;
|
2010-06-24 21:44:18 +00:00
|
|
|
public:
|
2013-04-16 01:16:13 +00:00
|
|
|
JSAutoCompartment(JSContext *cx, JSObject *target);
|
2012-08-27 20:32:51 +00:00
|
|
|
JSAutoCompartment(JSContext *cx, JSScript *target);
|
2012-08-22 01:42:53 +00:00
|
|
|
~JSAutoCompartment();
|
2010-06-24 21:44:18 +00:00
|
|
|
};
|
|
|
|
|
2014-06-19 07:21:14 +00:00
|
|
|
class JS_PUBLIC_API(JSAutoNullableCompartment)
|
2014-04-15 03:26:59 +00:00
|
|
|
{
|
|
|
|
JSContext *cx_;
|
|
|
|
JSCompartment *oldCompartment_;
|
|
|
|
public:
|
2014-06-19 07:21:14 +00:00
|
|
|
explicit JSAutoNullableCompartment(JSContext *cx, JSObject *targetOrNull);
|
|
|
|
~JSAutoNullableCompartment();
|
2014-04-15 03:26:59 +00:00
|
|
|
};
|
|
|
|
|
2013-10-07 16:42:55 +00:00
|
|
|
/* NB: This API is infallible; a nullptr return value does not indicate error. */
|
2012-08-27 20:32:51 +00:00
|
|
|
extern JS_PUBLIC_API(JSCompartment *)
|
2013-04-16 01:16:13 +00:00
|
|
|
JS_EnterCompartment(JSContext *cx, JSObject *target);
|
2012-08-27 20:32:51 +00:00
|
|
|
|
|
|
|
extern JS_PUBLIC_API(void)
|
|
|
|
JS_LeaveCompartment(JSContext *cx, JSCompartment *oldCompartment);
|
|
|
|
|
2012-02-29 20:23:53 +00:00
|
|
|
typedef void (*JSIterateCompartmentCallback)(JSRuntime *rt, void *data, JSCompartment *compartment);
|
2012-02-17 06:10:39 +00:00
|
|
|
|
|
|
|
/*
|
2015-01-12 22:19:27 +00:00
|
|
|
* This function calls |compartmentCallback| on every compartment. Beware that
|
2012-02-17 06:10:39 +00:00
|
|
|
* there is no guarantee that the compartment will survive after the callback
|
2015-03-17 16:26:03 +00:00
|
|
|
* returns.
|
2012-02-17 06:10:39 +00:00
|
|
|
*/
|
|
|
|
extern JS_PUBLIC_API(void)
|
2012-02-29 20:23:53 +00:00
|
|
|
JS_IterateCompartments(JSRuntime *rt, void *data,
|
2012-02-17 06:10:39 +00:00
|
|
|
JSIterateCompartmentCallback compartmentCallback);
|
|
|
|
|
2000-08-19 08:37:07 +00:00
|
|
|
/*
|
|
|
|
* Initialize standard JS class constructors, prototypes, and any top-level
|
|
|
|
* functions and constants associated with the standard classes (e.g. isNaN
|
|
|
|
* for Number).
|
|
|
|
*
|
|
|
|
* NB: This sets cx's global object to obj if it was null.
|
|
|
|
*/
|
2013-08-08 22:53:04 +00:00
|
|
|
extern JS_PUBLIC_API(bool)
|
2014-01-14 20:41:22 +00:00
|
|
|
JS_InitStandardClasses(JSContext *cx, JS::Handle<JSObject*> obj);
|
1998-03-28 02:44:41 +00:00
|
|
|
|
2000-08-19 08:37:07 +00:00
|
|
|
/*
|
|
|
|
* Resolve id, which must contain either a string or an int, to a standard
|
|
|
|
* class name in obj if possible, defining the class's constructor and/or
|
|
|
|
* prototype and storing true in *resolved. If id does not name a standard
|
|
|
|
* class or a top-level property induced by initializing a standard class,
|
|
|
|
* store false in *resolved and just return true. Return false on error,
|
2013-08-08 22:53:04 +00:00
|
|
|
* as usual for bool result-typed API entry points.
|
2000-08-19 08:37:07 +00:00
|
|
|
*
|
|
|
|
* This API can be called directly from a global object class's resolve op,
|
|
|
|
* to define standard classes lazily. The class's enumerate op should call
|
|
|
|
* JS_EnumerateStandardClasses(cx, obj), to define eagerly during for..in
|
|
|
|
* loops any classes not yet resolved lazily.
|
|
|
|
*/
|
2013-08-08 22:53:04 +00:00
|
|
|
extern JS_PUBLIC_API(bool)
|
2014-04-25 21:11:02 +00:00
|
|
|
JS_ResolveStandardClass(JSContext *cx, JS::HandleObject obj, JS::HandleId id, bool *resolved);
|
2000-08-19 08:37:07 +00:00
|
|
|
|
2013-08-08 22:53:04 +00:00
|
|
|
extern JS_PUBLIC_API(bool)
|
2014-01-15 10:31:00 +00:00
|
|
|
JS_EnumerateStandardClasses(JSContext *cx, JS::HandleObject obj);
|
2000-08-19 08:37:07 +00:00
|
|
|
|
2013-08-08 22:53:04 +00:00
|
|
|
extern JS_PUBLIC_API(bool)
|
2014-01-30 15:45:16 +00:00
|
|
|
JS_GetClassObject(JSContext *cx, JSProtoKey key, JS::MutableHandle<JSObject*> objp);
|
2006-04-19 00:22:43 +00:00
|
|
|
|
2013-08-08 22:53:04 +00:00
|
|
|
extern JS_PUBLIC_API(bool)
|
2014-01-15 01:19:07 +00:00
|
|
|
JS_GetClassPrototype(JSContext *cx, JSProtoKey key, JS::MutableHandle<JSObject*> objp);
|
2012-07-27 10:15:46 +00:00
|
|
|
|
2014-02-22 00:03:11 +00:00
|
|
|
namespace JS {
|
|
|
|
|
|
|
|
/*
|
2014-06-19 16:57:05 +00:00
|
|
|
* Determine if the given object is an instance/prototype/constructor for a standard
|
2014-02-22 00:03:11 +00:00
|
|
|
* class. If so, return the associated JSProtoKey. If not, return JSProto_Null.
|
|
|
|
*/
|
|
|
|
|
2012-07-27 10:15:46 +00:00
|
|
|
extern JS_PUBLIC_API(JSProtoKey)
|
2014-02-22 00:03:11 +00:00
|
|
|
IdentifyStandardInstance(JSObject *obj);
|
|
|
|
|
|
|
|
extern JS_PUBLIC_API(JSProtoKey)
|
|
|
|
IdentifyStandardPrototype(JSObject *obj);
|
|
|
|
|
|
|
|
extern JS_PUBLIC_API(JSProtoKey)
|
|
|
|
IdentifyStandardInstanceOrPrototype(JSObject *obj);
|
|
|
|
|
2014-06-19 16:57:05 +00:00
|
|
|
extern JS_PUBLIC_API(JSProtoKey)
|
|
|
|
IdentifyStandardConstructor(JSObject *obj);
|
|
|
|
|
2014-07-11 16:09:21 +00:00
|
|
|
extern JS_PUBLIC_API(void)
|
|
|
|
ProtoKeyToId(JSContext *cx, JSProtoKey key, JS::MutableHandleId idp);
|
|
|
|
|
2014-02-22 00:03:11 +00:00
|
|
|
} /* namespace JS */
|
2012-07-27 10:15:46 +00:00
|
|
|
|
2013-11-22 18:55:42 +00:00
|
|
|
extern JS_PUBLIC_API(JSProtoKey)
|
|
|
|
JS_IdToProtoKey(JSContext *cx, JS::HandleId id);
|
|
|
|
|
2012-02-10 22:49:39 +00:00
|
|
|
/*
|
|
|
|
* Returns the original value of |Function.prototype| from the global object in
|
|
|
|
* which |forObj| was created.
|
|
|
|
*/
|
|
|
|
extern JS_PUBLIC_API(JSObject *)
|
2014-01-22 01:03:20 +00:00
|
|
|
JS_GetFunctionPrototype(JSContext *cx, JS::HandleObject forObj);
|
2012-02-10 22:49:39 +00:00
|
|
|
|
2012-02-07 19:45:18 +00:00
|
|
|
/*
|
|
|
|
* Returns the original value of |Object.prototype| from the global object in
|
|
|
|
* which |forObj| was created.
|
|
|
|
*/
|
|
|
|
extern JS_PUBLIC_API(JSObject *)
|
2014-01-22 01:03:20 +00:00
|
|
|
JS_GetObjectPrototype(JSContext *cx, JS::HandleObject forObj);
|
2012-02-07 19:45:18 +00:00
|
|
|
|
2013-05-14 18:17:09 +00:00
|
|
|
/*
|
|
|
|
* Returns the original value of |Array.prototype| from the global object in
|
|
|
|
* which |forObj| was created.
|
|
|
|
*/
|
|
|
|
extern JS_PUBLIC_API(JSObject *)
|
2014-01-22 01:03:20 +00:00
|
|
|
JS_GetArrayPrototype(JSContext *cx, JS::HandleObject forObj);
|
2013-05-14 18:17:09 +00:00
|
|
|
|
2014-05-05 20:01:57 +00:00
|
|
|
/*
|
|
|
|
* Returns the original value of |Error.prototype| from the global
|
|
|
|
* object of the current compartment of cx.
|
|
|
|
*/
|
|
|
|
extern JS_PUBLIC_API(JSObject *)
|
|
|
|
JS_GetErrorPrototype(JSContext *cx);
|
|
|
|
|
2007-08-09 22:19:59 +00:00
|
|
|
extern JS_PUBLIC_API(JSObject *)
|
2013-04-16 01:16:13 +00:00
|
|
|
JS_GetGlobalForObject(JSContext *cx, JSObject *obj);
|
2007-08-09 22:19:59 +00:00
|
|
|
|
2013-08-08 22:53:04 +00:00
|
|
|
extern JS_PUBLIC_API(bool)
|
2013-04-16 01:16:13 +00:00
|
|
|
JS_IsGlobalObject(JSObject *obj);
|
2012-10-25 15:01:08 +00:00
|
|
|
|
2012-07-06 04:12:37 +00:00
|
|
|
/*
|
2013-10-07 16:42:55 +00:00
|
|
|
* May return nullptr, if |c| never had a global (e.g. the atoms compartment),
|
|
|
|
* or if |c|'s global has been collected.
|
2012-07-06 04:12:37 +00:00
|
|
|
*/
|
|
|
|
extern JS_PUBLIC_API(JSObject *)
|
|
|
|
JS_GetGlobalForCompartmentOrNull(JSContext *cx, JSCompartment *c);
|
|
|
|
|
2013-07-29 23:45:27 +00:00
|
|
|
namespace JS {
|
|
|
|
|
2010-05-21 12:27:00 +00:00
|
|
|
extern JS_PUBLIC_API(JSObject *)
|
2013-07-29 23:45:27 +00:00
|
|
|
CurrentGlobalOrNull(JSContext *cx);
|
|
|
|
|
|
|
|
}
|
2010-05-21 12:27:00 +00:00
|
|
|
|
2011-06-28 17:57:16 +00:00
|
|
|
/*
|
|
|
|
* Initialize the 'Reflect' object on a global object.
|
|
|
|
*/
|
|
|
|
extern JS_PUBLIC_API(JSObject *)
|
2014-01-22 01:03:20 +00:00
|
|
|
JS_InitReflect(JSContext *cx, JS::HandleObject global);
|
2014-09-23 13:25:31 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Add various profiling-related functions as properties of the given object.
|
|
|
|
* Defined in builtin/Profilers.cpp.
|
|
|
|
*/
|
|
|
|
extern JS_PUBLIC_API(bool)
|
|
|
|
JS_DefineProfilingFunctions(JSContext *cx, JS::HandleObject obj);
|
|
|
|
|
|
|
|
/* Defined in vm/Debugger.cpp. */
|
|
|
|
extern JS_PUBLIC_API(bool)
|
|
|
|
JS_DefineDebuggerObject(JSContext *cx, JS::HandleObject obj);
|
2011-06-28 17:57:16 +00:00
|
|
|
|
2010-04-02 20:07:41 +00:00
|
|
|
#ifdef JS_HAS_CTYPES
|
|
|
|
/*
|
|
|
|
* Initialize the 'ctypes' object on a global variable 'obj'. The 'ctypes'
|
|
|
|
* object will be sealed.
|
|
|
|
*/
|
2013-08-08 22:53:04 +00:00
|
|
|
extern JS_PUBLIC_API(bool)
|
2014-01-22 01:03:20 +00:00
|
|
|
JS_InitCTypesClass(JSContext *cx, JS::HandleObject global);
|
2010-09-13 17:54:02 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Convert a unicode string 'source' of length 'slen' to the platform native
|
|
|
|
* charset, returning a null-terminated string allocated with JS_malloc. On
|
|
|
|
* failure, this function should report an error.
|
|
|
|
*/
|
|
|
|
typedef char *
|
2014-07-22 04:43:21 +00:00
|
|
|
(* JSCTypesUnicodeToNativeFun)(JSContext *cx, const char16_t *source, size_t slen);
|
2010-09-13 17:54:02 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Set of function pointers that ctypes can use for various internal functions.
|
2013-10-07 16:42:55 +00:00
|
|
|
* See JS_SetCTypesCallbacks below. Providing nullptr for a function is safe,
|
2010-09-13 17:54:02 +00:00
|
|
|
* and will result in the applicable ctypes functionality not being available.
|
|
|
|
*/
|
|
|
|
struct JSCTypesCallbacks {
|
|
|
|
JSCTypesUnicodeToNativeFun unicodeToNative;
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct JSCTypesCallbacks JSCTypesCallbacks;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set the callbacks on the provided 'ctypesObj' object. 'callbacks' should be a
|
|
|
|
* pointer to static data that exists for the lifetime of 'ctypesObj', but it
|
|
|
|
* may safely be altered after calling this function and without having
|
|
|
|
* to call this function again.
|
|
|
|
*/
|
2012-02-05 20:07:23 +00:00
|
|
|
extern JS_PUBLIC_API(void)
|
2014-12-17 00:30:39 +00:00
|
|
|
JS_SetCTypesCallbacks(JSObject *ctypesObj, const JSCTypesCallbacks *callbacks);
|
2010-04-02 20:07:41 +00:00
|
|
|
#endif
|
|
|
|
|
1998-04-24 00:31:11 +00:00
|
|
|
extern JS_PUBLIC_API(void *)
|
1998-03-28 02:44:41 +00:00
|
|
|
JS_malloc(JSContext *cx, size_t nbytes);
|
|
|
|
|
1998-04-24 00:31:11 +00:00
|
|
|
extern JS_PUBLIC_API(void *)
|
2014-08-05 21:06:35 +00:00
|
|
|
JS_realloc(JSContext *cx, void *p, size_t oldBytes, size_t newBytes);
|
1998-03-28 02:44:41 +00:00
|
|
|
|
2012-03-19 14:34:55 +00:00
|
|
|
/*
|
|
|
|
* A wrapper for js_free(p) that may delay js_free(p) invocation as a
|
|
|
|
* performance optimization.
|
2013-10-07 16:42:55 +00:00
|
|
|
* cx may be nullptr.
|
2012-03-19 14:34:55 +00:00
|
|
|
*/
|
1998-04-24 00:31:11 +00:00
|
|
|
extern JS_PUBLIC_API(void)
|
1998-03-28 02:44:41 +00:00
|
|
|
JS_free(JSContext *cx, void *p);
|
|
|
|
|
2012-03-19 14:34:55 +00:00
|
|
|
/*
|
|
|
|
* A wrapper for js_free(p) that may delay js_free(p) invocation as a
|
|
|
|
* performance optimization as specified by the given JSFreeOp instance.
|
|
|
|
*/
|
|
|
|
extern JS_PUBLIC_API(void)
|
|
|
|
JS_freeop(JSFreeOp *fop, void *p);
|
|
|
|
|
2012-03-19 14:34:58 +00:00
|
|
|
extern JS_PUBLIC_API(JSFreeOp *)
|
2012-05-19 19:56:17 +00:00
|
|
|
JS_GetDefaultFreeOp(JSRuntime *rt);
|
2012-03-19 14:34:58 +00:00
|
|
|
|
2009-10-29 18:48:18 +00:00
|
|
|
extern JS_PUBLIC_API(void)
|
|
|
|
JS_updateMallocCounter(JSContext *cx, size_t nbytes);
|
|
|
|
|
1998-04-24 00:31:11 +00:00
|
|
|
extern JS_PUBLIC_API(char *)
|
1998-03-28 02:44:41 +00:00
|
|
|
JS_strdup(JSContext *cx, const char *s);
|
|
|
|
|
2013-02-08 02:04:11 +00:00
|
|
|
/* Duplicate a string. Does not report an error on failure. */
|
|
|
|
extern JS_PUBLIC_API(char *)
|
|
|
|
JS_strdup(JSRuntime *rt, const char *s);
|
|
|
|
|
2007-05-01 10:09:46 +00:00
|
|
|
/*
|
|
|
|
* Register externally maintained GC roots.
|
|
|
|
*
|
|
|
|
* traceOp: the trace operation. For each root the implementation should call
|
|
|
|
* JS_CallTracer whenever the root contains a traceable thing.
|
|
|
|
* data: the data argument to pass to each invocation of traceOp.
|
|
|
|
*/
|
2013-08-08 22:53:04 +00:00
|
|
|
extern JS_PUBLIC_API(bool)
|
2013-07-03 07:24:32 +00:00
|
|
|
JS_AddExtraGCRootsTracer(JSRuntime *rt, JSTraceDataOp traceOp, void *data);
|
|
|
|
|
|
|
|
/* Undo a call to JS_AddExtraGCRootsTracer. */
|
2007-05-01 10:09:46 +00:00
|
|
|
extern JS_PUBLIC_API(void)
|
2013-07-03 07:24:32 +00:00
|
|
|
JS_RemoveExtraGCRootsTracer(JSRuntime *rt, JSTraceDataOp traceOp, void *data);
|
2007-05-01 10:09:46 +00:00
|
|
|
|
2007-04-17 06:53:37 +00:00
|
|
|
/*
|
|
|
|
* Garbage collector API.
|
|
|
|
*/
|
1998-04-24 00:31:11 +00:00
|
|
|
extern JS_PUBLIC_API(void)
|
2012-03-28 10:13:30 +00:00
|
|
|
JS_GC(JSRuntime *rt);
|
1998-03-28 02:44:41 +00:00
|
|
|
|
1998-04-24 00:31:11 +00:00
|
|
|
extern JS_PUBLIC_API(void)
|
1998-03-28 02:44:41 +00:00
|
|
|
JS_MaybeGC(JSContext *cx);
|
|
|
|
|
2012-02-29 20:23:38 +00:00
|
|
|
extern JS_PUBLIC_API(void)
|
2013-07-09 14:28:15 +00:00
|
|
|
JS_SetGCCallback(JSRuntime *rt, JSGCCallback cb, void *data);
|
1998-04-24 00:31:11 +00:00
|
|
|
|
2014-05-16 23:40:34 +00:00
|
|
|
extern JS_PUBLIC_API(bool)
|
|
|
|
JS_AddFinalizeCallback(JSRuntime *rt, JSFinalizeCallback cb, void *data);
|
|
|
|
|
2012-02-29 20:23:38 +00:00
|
|
|
extern JS_PUBLIC_API(void)
|
2014-05-16 23:40:34 +00:00
|
|
|
JS_RemoveFinalizeCallback(JSRuntime *rt, JSFinalizeCallback cb);
|
2000-05-14 23:00:51 +00:00
|
|
|
|
2013-08-08 22:53:04 +00:00
|
|
|
extern JS_PUBLIC_API(bool)
|
2007-04-17 06:53:37 +00:00
|
|
|
JS_IsGCMarkingTracer(JSTracer *trc);
|
|
|
|
|
2013-03-28 20:27:29 +00:00
|
|
|
/*
|
2014-09-24 11:54:11 +00:00
|
|
|
* Weak pointers and garbage collection
|
|
|
|
*
|
|
|
|
* Weak pointers are by their nature not marked as part of garbage collection,
|
|
|
|
* but they may need to be updated in two cases after a GC:
|
|
|
|
*
|
|
|
|
* 1) Their referent was found not to be live and is about to be finalized
|
|
|
|
* 2) Their referent has been moved by a compacting GC
|
|
|
|
*
|
|
|
|
* To handle this, any part of the system that maintain weak pointers to
|
|
|
|
* JavaScript GC things must register a callback with
|
|
|
|
* JS_(Add,Remove)WeakPointerCallback(). This callback must then call
|
|
|
|
* JS_UpdateWeakPointerAfterGC() on all weak pointers it knows about.
|
|
|
|
*
|
|
|
|
* The argument to JS_UpdateWeakPointerAfterGC() is an in-out param. If the
|
|
|
|
* referent is about to be finalized the pointer will be set to null. If the
|
|
|
|
* referent has been moved then the pointer will be updated to point to the new
|
|
|
|
* location.
|
2013-03-28 20:27:29 +00:00
|
|
|
*
|
|
|
|
* Callers of this method are responsible for updating any state that is
|
|
|
|
* dependent on the object's address. For example, if the object's address is
|
|
|
|
* used as a key in a hashtable, then the object must be removed and
|
|
|
|
* re-inserted with the correct hash.
|
|
|
|
*/
|
2013-06-05 23:40:02 +00:00
|
|
|
|
2013-08-08 22:53:04 +00:00
|
|
|
extern JS_PUBLIC_API(bool)
|
2014-09-24 11:54:11 +00:00
|
|
|
JS_AddWeakPointerCallback(JSRuntime *rt, JSWeakPointerCallback cb, void *data);
|
|
|
|
|
|
|
|
extern JS_PUBLIC_API(void)
|
|
|
|
JS_RemoveWeakPointerCallback(JSRuntime *rt, JSWeakPointerCallback cb);
|
|
|
|
|
|
|
|
extern JS_PUBLIC_API(void)
|
|
|
|
JS_UpdateWeakPointerAfterGC(JS::Heap<JSObject *> *objp);
|
|
|
|
|
|
|
|
extern JS_PUBLIC_API(void)
|
|
|
|
JS_UpdateWeakPointerAfterGCUnbarriered(JSObject **objp);
|
2001-02-02 08:44:24 +00:00
|
|
|
|
2006-02-22 05:52:13 +00:00
|
|
|
typedef enum JSGCParamKey {
|
2008-01-30 02:11:30 +00:00
|
|
|
/* Maximum nominal heap before last ditch GC. */
|
|
|
|
JSGC_MAX_BYTES = 0,
|
|
|
|
|
2009-08-25 21:42:42 +00:00
|
|
|
/* Number of JS_malloc bytes before last ditch GC. */
|
|
|
|
JSGC_MAX_MALLOC_BYTES = 1,
|
|
|
|
|
2009-01-27 17:21:51 +00:00
|
|
|
/* Amount of bytes allocated by the GC. */
|
2011-05-11 05:37:11 +00:00
|
|
|
JSGC_BYTES = 3,
|
2009-01-27 17:21:51 +00:00
|
|
|
|
2014-07-15 20:49:43 +00:00
|
|
|
/* Number of times GC has been invoked. Includes both major and minor GC. */
|
2011-05-11 05:37:11 +00:00
|
|
|
JSGC_NUMBER = 4,
|
2009-04-22 23:52:59 +00:00
|
|
|
|
|
|
|
/* Max size of the code cache in bytes. */
|
2011-05-11 05:37:11 +00:00
|
|
|
JSGC_MAX_CODE_CACHE_BYTES = 5,
|
2011-01-10 06:57:21 +00:00
|
|
|
|
|
|
|
/* Select GC mode. */
|
2011-05-11 05:37:11 +00:00
|
|
|
JSGC_MODE = 6,
|
2011-02-20 06:59:49 +00:00
|
|
|
|
2011-09-23 14:14:26 +00:00
|
|
|
/* Number of cached empty GC chunks. */
|
2011-07-29 22:17:41 +00:00
|
|
|
JSGC_UNUSED_CHUNKS = 7,
|
|
|
|
|
|
|
|
/* Total number of allocated GC chunks. */
|
2012-02-17 22:35:20 +00:00
|
|
|
JSGC_TOTAL_CHUNKS = 8,
|
|
|
|
|
|
|
|
/* Max milliseconds to spend in an incremental GC slice. */
|
2012-02-24 18:42:42 +00:00
|
|
|
JSGC_SLICE_TIME_BUDGET = 9,
|
|
|
|
|
|
|
|
/* Maximum size the GC mark stack can grow to. */
|
2012-07-11 18:09:53 +00:00
|
|
|
JSGC_MARK_STACK_LIMIT = 10,
|
|
|
|
|
|
|
|
/*
|
|
|
|
* GCs less than this far apart in time will be considered 'high-frequency GCs'.
|
|
|
|
* See setGCLastBytes in jsgc.cpp.
|
|
|
|
*/
|
|
|
|
JSGC_HIGH_FREQUENCY_TIME_LIMIT = 11,
|
|
|
|
|
|
|
|
/* Start of dynamic heap growth. */
|
|
|
|
JSGC_HIGH_FREQUENCY_LOW_LIMIT = 12,
|
|
|
|
|
|
|
|
/* End of dynamic heap growth. */
|
|
|
|
JSGC_HIGH_FREQUENCY_HIGH_LIMIT = 13,
|
|
|
|
|
|
|
|
/* Upper bound of heap growth. */
|
|
|
|
JSGC_HIGH_FREQUENCY_HEAP_GROWTH_MAX = 14,
|
|
|
|
|
|
|
|
/* Lower bound of heap growth. */
|
|
|
|
JSGC_HIGH_FREQUENCY_HEAP_GROWTH_MIN = 15,
|
|
|
|
|
|
|
|
/* Heap growth for low frequency GCs. */
|
|
|
|
JSGC_LOW_FREQUENCY_HEAP_GROWTH = 16,
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If false, the heap growth factor is fixed at 3. If true, it is determined
|
|
|
|
* based on whether GCs are high- or low- frequency.
|
|
|
|
*/
|
|
|
|
JSGC_DYNAMIC_HEAP_GROWTH = 17,
|
|
|
|
|
|
|
|
/* If true, high-frequency GCs will use a longer mark slice. */
|
2012-08-22 18:28:34 +00:00
|
|
|
JSGC_DYNAMIC_MARK_SLICE = 18,
|
|
|
|
|
2012-10-26 23:06:19 +00:00
|
|
|
/* Lower limit after which we limit the heap growth. */
|
2013-08-15 11:45:30 +00:00
|
|
|
JSGC_ALLOCATION_THRESHOLD = 19,
|
2013-06-21 01:06:53 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* We decommit memory lazily. If more than this number of megabytes is
|
|
|
|
* available to be decommitted, then JS_MaybeGC will trigger a shrinking GC
|
|
|
|
* to decommit it.
|
|
|
|
*/
|
2014-07-16 09:01:19 +00:00
|
|
|
JSGC_DECOMMIT_THRESHOLD = 20,
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We try to keep at least this many unused chunks in the free chunk pool at
|
|
|
|
* all times, even after a shrinking GC.
|
|
|
|
*/
|
|
|
|
JSGC_MIN_EMPTY_CHUNK_COUNT = 21,
|
|
|
|
|
|
|
|
/* We never keep more than this many unused chunks in the free chunk pool. */
|
2015-02-02 14:39:34 +00:00
|
|
|
JSGC_MAX_EMPTY_CHUNK_COUNT = 22,
|
|
|
|
|
|
|
|
/* Whether compacting GC is enabled. */
|
|
|
|
JSGC_COMPACTING_ENABLED = 23
|
2006-02-22 05:52:13 +00:00
|
|
|
} JSGCParamKey;
|
|
|
|
|
|
|
|
extern JS_PUBLIC_API(void)
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-09 03:54:10 +00:00
|
|
|
JS_SetGCParameter(JSRuntime *rt, JSGCParamKey key, uint32_t value);
|
2006-02-22 05:52:13 +00:00
|
|
|
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-09 03:54:10 +00:00
|
|
|
extern JS_PUBLIC_API(uint32_t)
|
2009-01-27 17:21:51 +00:00
|
|
|
JS_GetGCParameter(JSRuntime *rt, JSGCParamKey key);
|
|
|
|
|
2009-04-22 23:52:59 +00:00
|
|
|
extern JS_PUBLIC_API(void)
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-09 03:54:10 +00:00
|
|
|
JS_SetGCParameterForThread(JSContext *cx, JSGCParamKey key, uint32_t value);
|
2009-04-22 23:52:59 +00:00
|
|
|
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-09 03:54:10 +00:00
|
|
|
extern JS_PUBLIC_API(uint32_t)
|
2009-04-22 23:52:59 +00:00
|
|
|
JS_GetGCParameterForThread(JSContext *cx, JSGCParamKey key);
|
|
|
|
|
2013-12-17 13:46:46 +00:00
|
|
|
extern JS_PUBLIC_API(void)
|
|
|
|
JS_SetGCParametersBasedOnAvailableMemory(JSRuntime *rt, uint32_t availMem);
|
|
|
|
|
2000-09-02 20:37:37 +00:00
|
|
|
/*
|
|
|
|
* Create a new JSString whose chars member refers to external memory, i.e.,
|
2012-02-07 18:44:54 +00:00
|
|
|
* memory requiring application-specific finalization.
|
2011-04-21 01:34:49 +00:00
|
|
|
*/
|
|
|
|
extern JS_PUBLIC_API(JSString *)
|
2014-07-22 04:43:21 +00:00
|
|
|
JS_NewExternalString(JSContext *cx, const char16_t *chars, size_t length,
|
2012-02-07 18:44:54 +00:00
|
|
|
const JSStringFinalizer *fin);
|
2011-04-21 01:34:49 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Return whether 'str' was created with JS_NewExternalString or
|
|
|
|
* JS_NewExternalStringWithClosure.
|
|
|
|
*/
|
2013-08-08 22:53:04 +00:00
|
|
|
extern JS_PUBLIC_API(bool)
|
2012-02-07 18:44:54 +00:00
|
|
|
JS_IsExternalString(JSString *str);
|
2011-04-21 01:34:49 +00:00
|
|
|
|
|
|
|
/*
|
2014-12-29 18:22:51 +00:00
|
|
|
* Return the 'fin' arg passed to JS_NewExternalString.
|
2011-04-21 01:34:49 +00:00
|
|
|
*/
|
2012-02-07 18:44:54 +00:00
|
|
|
extern JS_PUBLIC_API(const JSStringFinalizer *)
|
|
|
|
JS_GetExternalStringFinalizer(JSString *str);
|
2000-09-02 20:37:37 +00:00
|
|
|
|
2010-05-19 08:29:05 +00:00
|
|
|
/*
|
|
|
|
* Set the size of the native stack that should not be exceed. To disable
|
|
|
|
* stack size checking pass 0.
|
2013-08-28 18:04:15 +00:00
|
|
|
*
|
|
|
|
* SpiderMonkey allows for a distinction between system code (such as GCs, which
|
|
|
|
* may incidentally be triggered by script but are not strictly performed on
|
|
|
|
* behalf of such script), trusted script (as determined by JS_SetTrustedPrincipals),
|
|
|
|
* and untrusted script. Each kind of code may have a different stack quota,
|
|
|
|
* allowing embedders to keep higher-priority machinery running in the face of
|
|
|
|
* scripted stack exhaustion by something else.
|
|
|
|
*
|
|
|
|
* The stack quotas for each kind of code should be monotonically descending,
|
|
|
|
* and may be specified with this function. If 0 is passed for a given kind
|
|
|
|
* of code, it defaults to the value of the next-highest-priority kind.
|
2014-10-30 22:35:35 +00:00
|
|
|
*
|
|
|
|
* This function may only be called immediately after the runtime is initialized
|
|
|
|
* and before any code is executed and/or interrupts requested.
|
2010-05-19 08:29:05 +00:00
|
|
|
*/
|
|
|
|
extern JS_PUBLIC_API(void)
|
2013-08-28 18:04:15 +00:00
|
|
|
JS_SetNativeStackQuota(JSRuntime *cx, size_t systemCodeStackSize,
|
|
|
|
size_t trustedScriptStackSize = 0,
|
|
|
|
size_t untrustedScriptStackSize = 0);
|
2010-05-19 08:29:05 +00:00
|
|
|
|
1998-03-28 02:44:41 +00:00
|
|
|
/************************************************************************/
|
|
|
|
|
2012-03-02 02:54:01 +00:00
|
|
|
extern JS_PUBLIC_API(int)
|
2011-10-25 23:07:42 +00:00
|
|
|
JS_IdArrayLength(JSContext *cx, JSIdArray *ida);
|
|
|
|
|
|
|
|
extern JS_PUBLIC_API(jsid)
|
2014-06-19 09:54:19 +00:00
|
|
|
JS_IdArrayGet(JSContext *cx, JSIdArray *ida, unsigned index);
|
1998-04-24 00:31:11 +00:00
|
|
|
|
|
|
|
extern JS_PUBLIC_API(void)
|
|
|
|
JS_DestroyIdArray(JSContext *cx, JSIdArray *ida);
|
1998-03-28 02:44:41 +00:00
|
|
|
|
2012-01-11 08:23:09 +00:00
|
|
|
namespace JS {
|
|
|
|
|
2012-12-27 17:20:22 +00:00
|
|
|
class AutoIdArray : private AutoGCRooter
|
|
|
|
{
|
2012-01-11 08:23:09 +00:00
|
|
|
public:
|
2012-12-27 17:20:22 +00:00
|
|
|
AutoIdArray(JSContext *cx, JSIdArray *ida
|
|
|
|
MOZ_GUARD_OBJECT_NOTIFIER_PARAM)
|
2012-02-29 12:18:16 +00:00
|
|
|
: AutoGCRooter(cx, IDARRAY), context(cx), idArray(ida)
|
2012-01-11 08:23:09 +00:00
|
|
|
{
|
2012-12-27 17:20:22 +00:00
|
|
|
MOZ_GUARD_OBJECT_NOTIFIER_INIT;
|
2012-01-11 08:23:09 +00:00
|
|
|
}
|
|
|
|
~AutoIdArray() {
|
|
|
|
if (idArray)
|
|
|
|
JS_DestroyIdArray(context, idArray);
|
|
|
|
}
|
2014-05-12 16:50:46 +00:00
|
|
|
bool operator!() const {
|
2012-01-11 08:23:09 +00:00
|
|
|
return !idArray;
|
|
|
|
}
|
|
|
|
jsid operator[](size_t i) const {
|
2014-10-01 17:17:51 +00:00
|
|
|
MOZ_ASSERT(idArray);
|
2014-06-19 09:54:19 +00:00
|
|
|
return JS_IdArrayGet(context, idArray, unsigned(i));
|
2012-01-11 08:23:09 +00:00
|
|
|
}
|
|
|
|
size_t length() const {
|
|
|
|
return JS_IdArrayLength(context, idArray);
|
|
|
|
}
|
|
|
|
|
|
|
|
friend void AutoGCRooter::trace(JSTracer *trc);
|
|
|
|
|
|
|
|
JSIdArray *steal() {
|
|
|
|
JSIdArray *copy = idArray;
|
2013-10-07 16:42:55 +00:00
|
|
|
idArray = nullptr;
|
2012-01-11 08:23:09 +00:00
|
|
|
return copy;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
inline void trace(JSTracer *trc);
|
|
|
|
|
|
|
|
private:
|
2012-02-29 12:18:16 +00:00
|
|
|
JSContext *context;
|
2012-01-11 08:23:09 +00:00
|
|
|
JSIdArray *idArray;
|
2012-12-27 17:20:22 +00:00
|
|
|
MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER
|
2012-01-11 08:23:09 +00:00
|
|
|
|
|
|
|
/* No copy or assignment semantics. */
|
2015-01-06 23:35:02 +00:00
|
|
|
AutoIdArray(AutoIdArray &ida) = delete;
|
|
|
|
void operator=(AutoIdArray &ida) = delete;
|
2012-01-11 08:23:09 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} /* namespace JS */
|
|
|
|
|
2013-08-08 22:53:04 +00:00
|
|
|
extern JS_PUBLIC_API(bool)
|
2014-04-02 14:28:03 +00:00
|
|
|
JS_ValueToId(JSContext *cx, JS::HandleValue v, JS::MutableHandleId idp);
|
|
|
|
|
|
|
|
extern JS_PUBLIC_API(bool)
|
|
|
|
JS_StringToId(JSContext *cx, JS::HandleString s, JS::MutableHandleId idp);
|
1998-04-24 00:31:11 +00:00
|
|
|
|
2013-08-08 22:53:04 +00:00
|
|
|
extern JS_PUBLIC_API(bool)
|
2014-01-17 18:08:51 +00:00
|
|
|
JS_IdToValue(JSContext *cx, jsid id, JS::MutableHandle<JS::Value> vp);
|
1998-04-24 00:31:11 +00:00
|
|
|
|
2011-10-14 23:27:50 +00:00
|
|
|
/*
|
|
|
|
* Invoke the [[DefaultValue]] hook (see ES5 8.6.2) with the provided hint on
|
|
|
|
* the specified object, computing a primitive default value for the object.
|
|
|
|
* The hint must be JSTYPE_STRING, JSTYPE_NUMBER, or JSTYPE_VOID (no hint). On
|
|
|
|
* success the resulting value is stored in *vp.
|
|
|
|
*/
|
2013-08-08 22:53:04 +00:00
|
|
|
extern JS_PUBLIC_API(bool)
|
2014-01-14 20:41:22 +00:00
|
|
|
JS_DefaultValue(JSContext *cx, JS::Handle<JSObject*> obj, JSType hint,
|
|
|
|
JS::MutableHandle<JS::Value> vp);
|
2011-10-14 23:27:50 +00:00
|
|
|
|
2013-08-08 22:53:04 +00:00
|
|
|
extern JS_PUBLIC_API(bool)
|
2014-01-15 10:31:00 +00:00
|
|
|
JS_PropertyStub(JSContext *cx, JS::HandleObject obj, JS::HandleId id,
|
|
|
|
JS::MutableHandleValue vp);
|
2010-05-19 16:55:27 +00:00
|
|
|
|
2013-08-08 22:53:04 +00:00
|
|
|
extern JS_PUBLIC_API(bool)
|
2015-02-04 01:51:40 +00:00
|
|
|
JS_StrictPropertyStub(JSContext *cx, JS::HandleObject obj, JS::HandleId id,
|
|
|
|
JS::MutableHandleValue vp, JS::ObjectOpResult &result);
|
2011-02-09 19:31:40 +00:00
|
|
|
|
2014-09-15 13:13:05 +00:00
|
|
|
template<typename T>
|
|
|
|
struct JSConstScalarSpec {
|
2014-09-15 13:13:08 +00:00
|
|
|
const char *name;
|
2014-09-15 13:13:05 +00:00
|
|
|
T val;
|
1998-03-28 02:44:41 +00:00
|
|
|
};
|
|
|
|
|
2014-09-15 13:13:05 +00:00
|
|
|
typedef JSConstScalarSpec<double> JSConstDoubleSpec;
|
|
|
|
typedef JSConstScalarSpec<int32_t> JSConstIntegerSpec;
|
|
|
|
|
2013-08-22 05:28:12 +00:00
|
|
|
struct JSJitInfo;
|
2012-08-08 05:26:18 +00:00
|
|
|
|
|
|
|
/*
|
2014-10-29 19:06:31 +00:00
|
|
|
* Wrapper to relace JSNative for JSPropertySpecs and JSFunctionSpecs. This will
|
|
|
|
* allow us to pass one JSJitInfo per function with the property/function spec,
|
|
|
|
* without additional field overhead.
|
2012-08-08 05:26:19 +00:00
|
|
|
*/
|
|
|
|
typedef struct JSNativeWrapper {
|
|
|
|
JSNative op;
|
|
|
|
const JSJitInfo *info;
|
|
|
|
} JSNativeWrapper;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Macro static initializers which make it easy to pass no JSJitInfo as part of a
|
|
|
|
* JSPropertySpec or JSFunctionSpec.
|
2012-08-08 05:26:18 +00:00
|
|
|
*/
|
2014-10-29 19:06:31 +00:00
|
|
|
#define JSNATIVE_WRAPPER(native) { {native, nullptr} }
|
2012-08-08 05:26:18 +00:00
|
|
|
|
1998-03-28 02:44:41 +00:00
|
|
|
/*
|
|
|
|
* To define an array element rather than a named property member, cast the
|
|
|
|
* element's index to (const char *) and initialize name with it, and set the
|
|
|
|
* JSPROP_INDEX bit in flags.
|
|
|
|
*/
|
|
|
|
struct JSPropertySpec {
|
2014-01-10 17:11:31 +00:00
|
|
|
struct SelfHostedWrapper {
|
|
|
|
void *unused;
|
|
|
|
const char *funname;
|
|
|
|
};
|
|
|
|
|
2012-08-08 05:26:18 +00:00
|
|
|
const char *name;
|
|
|
|
uint8_t flags;
|
2014-01-10 17:11:31 +00:00
|
|
|
union {
|
2014-10-29 19:06:31 +00:00
|
|
|
JSNativeWrapper native;
|
2014-01-10 17:11:31 +00:00
|
|
|
SelfHostedWrapper selfHosted;
|
|
|
|
} getter;
|
|
|
|
union {
|
2014-10-29 19:06:31 +00:00
|
|
|
JSNativeWrapper native;
|
2014-01-10 17:11:31 +00:00
|
|
|
SelfHostedWrapper selfHosted;
|
|
|
|
} setter;
|
|
|
|
|
2014-10-29 19:06:31 +00:00
|
|
|
bool isSelfHosted() const {
|
|
|
|
#ifdef DEBUG
|
|
|
|
// Verify that our accessors match our JSPROP_GETTER flag.
|
|
|
|
if (flags & JSPROP_GETTER)
|
|
|
|
checkAccessorsAreSelfHosted();
|
|
|
|
else
|
|
|
|
checkAccessorsAreNative();
|
|
|
|
#endif
|
|
|
|
return (flags & JSPROP_GETTER);
|
|
|
|
}
|
|
|
|
|
|
|
|
static_assert(sizeof(SelfHostedWrapper) == sizeof(JSNativeWrapper),
|
|
|
|
"JSPropertySpec::getter/setter must be compact");
|
|
|
|
static_assert(offsetof(SelfHostedWrapper, funname) == offsetof(JSNativeWrapper, info),
|
2014-10-27 00:23:15 +00:00
|
|
|
"JS_SELF_HOSTED* macros below require that "
|
|
|
|
"SelfHostedWrapper::funname overlay "
|
2014-10-29 19:06:31 +00:00
|
|
|
"JSNativeWrapper::info");
|
|
|
|
private:
|
|
|
|
void checkAccessorsAreNative() const {
|
|
|
|
MOZ_ASSERT(getter.native.op);
|
|
|
|
// We may not have a setter at all. So all we can assert here, for the
|
|
|
|
// native case is that if we have a jitinfo for the setter then we have
|
|
|
|
// a setter op too. This is good enough to make sure we don't have a
|
|
|
|
// SelfHostedWrapper for the setter.
|
|
|
|
MOZ_ASSERT_IF(setter.native.info, setter.native.op);
|
|
|
|
}
|
|
|
|
|
|
|
|
void checkAccessorsAreSelfHosted() const {
|
|
|
|
MOZ_ASSERT(!getter.selfHosted.unused);
|
|
|
|
MOZ_ASSERT(!setter.selfHosted.unused);
|
|
|
|
}
|
1998-03-28 02:44:41 +00:00
|
|
|
};
|
|
|
|
|
2013-08-21 22:33:11 +00:00
|
|
|
namespace JS {
|
|
|
|
namespace detail {
|
|
|
|
|
|
|
|
/* NEVER DEFINED, DON'T USE. For use by JS_CAST_NATIVE_TO only. */
|
|
|
|
inline int CheckIsNative(JSNative native);
|
|
|
|
|
2014-01-10 17:11:31 +00:00
|
|
|
/* NEVER DEFINED, DON'T USE. For use by JS_CAST_STRING_TO only. */
|
|
|
|
template<size_t N>
|
|
|
|
inline int
|
|
|
|
CheckIsCharacterLiteral(const char (&arr)[N]);
|
|
|
|
|
2014-10-29 19:06:31 +00:00
|
|
|
/* NEVER DEFINED, DON'T USE. For use by JS_PROPERTYOP_GETTER only. */
|
2015-01-30 19:56:15 +00:00
|
|
|
inline int CheckIsGetterOp(JSGetterOp op);
|
2014-10-29 19:06:31 +00:00
|
|
|
|
|
|
|
/* NEVER DEFINED, DON'T USE. For use by JS_PROPERTYOP_SETTER only. */
|
2015-01-30 19:56:15 +00:00
|
|
|
inline int CheckIsSetterOp(JSSetterOp op);
|
2014-10-29 19:06:31 +00:00
|
|
|
|
|
|
|
|
2013-08-21 22:33:11 +00:00
|
|
|
} // namespace detail
|
|
|
|
} // namespace JS
|
|
|
|
|
|
|
|
#define JS_CAST_NATIVE_TO(v, To) \
|
|
|
|
(static_cast<void>(sizeof(JS::detail::CheckIsNative(v))), \
|
|
|
|
reinterpret_cast<To>(v))
|
|
|
|
|
2014-01-10 17:11:31 +00:00
|
|
|
#define JS_CAST_STRING_TO(s, To) \
|
|
|
|
(static_cast<void>(sizeof(JS::detail::CheckIsCharacterLiteral(s))), \
|
|
|
|
reinterpret_cast<To>(s))
|
|
|
|
|
2013-09-27 21:43:38 +00:00
|
|
|
#define JS_CHECK_ACCESSOR_FLAGS(flags) \
|
2014-10-29 19:06:31 +00:00
|
|
|
(static_cast<mozilla::EnableIf<!((flags) & (JSPROP_READONLY | JSPROP_SHARED | JSPROP_PROPOP_ACCESSORS))>::Type>(0), \
|
2013-09-27 21:43:38 +00:00
|
|
|
(flags))
|
|
|
|
|
2014-10-29 19:06:31 +00:00
|
|
|
#define JS_PROPERTYOP_GETTER(v) \
|
2015-01-30 19:56:15 +00:00
|
|
|
(static_cast<void>(sizeof(JS::detail::CheckIsGetterOp(v))), \
|
2014-10-29 19:06:31 +00:00
|
|
|
reinterpret_cast<JSNative>(v))
|
|
|
|
|
|
|
|
#define JS_PROPERTYOP_SETTER(v) \
|
2015-01-30 19:56:15 +00:00
|
|
|
(static_cast<void>(sizeof(JS::detail::CheckIsSetterOp(v))), \
|
2014-10-29 19:06:31 +00:00
|
|
|
reinterpret_cast<JSNative>(v))
|
|
|
|
|
|
|
|
#define JS_STUBGETTER JS_PROPERTYOP_GETTER(JS_PropertyStub)
|
|
|
|
|
|
|
|
#define JS_STUBSETTER JS_PROPERTYOP_SETTER(JS_StrictPropertyStub)
|
|
|
|
|
2013-08-21 22:33:11 +00:00
|
|
|
/*
|
2014-10-29 19:06:31 +00:00
|
|
|
* JSPropertySpec uses JSNativeWrapper. These macros encapsulate the definition
|
|
|
|
* of JSNative-backed JSPropertySpecs, by defining the JSNativeWrappers for
|
|
|
|
* them.
|
2013-08-21 22:33:11 +00:00
|
|
|
*/
|
|
|
|
#define JS_PSG(name, getter, flags) \
|
2014-03-21 06:24:21 +00:00
|
|
|
{name, \
|
2014-10-29 19:06:31 +00:00
|
|
|
uint8_t(JS_CHECK_ACCESSOR_FLAGS(flags) | JSPROP_SHARED), \
|
|
|
|
JSNATIVE_WRAPPER(getter), \
|
|
|
|
JSNATIVE_WRAPPER(nullptr)}
|
2013-08-21 22:33:11 +00:00
|
|
|
#define JS_PSGS(name, getter, setter, flags) \
|
2014-03-21 06:24:21 +00:00
|
|
|
{name, \
|
2014-10-29 19:06:31 +00:00
|
|
|
uint8_t(JS_CHECK_ACCESSOR_FLAGS(flags) | JSPROP_SHARED), \
|
|
|
|
JSNATIVE_WRAPPER(getter), \
|
|
|
|
JSNATIVE_WRAPPER(setter)}
|
2013-11-20 20:11:45 +00:00
|
|
|
#define JS_SELF_HOSTED_GET(name, getterName, flags) \
|
2014-03-21 06:24:21 +00:00
|
|
|
{name, \
|
2013-11-20 20:11:45 +00:00
|
|
|
uint8_t(JS_CHECK_ACCESSOR_FLAGS(flags) | JSPROP_SHARED | JSPROP_GETTER), \
|
2015-02-22 06:23:00 +00:00
|
|
|
{ { nullptr, JS_CAST_STRING_TO(getterName, const JSJitInfo *) } }, \
|
2014-10-29 19:06:31 +00:00
|
|
|
JSNATIVE_WRAPPER(nullptr) }
|
2013-11-20 20:11:45 +00:00
|
|
|
#define JS_SELF_HOSTED_GETSET(name, getterName, setterName, flags) \
|
2014-03-21 06:24:21 +00:00
|
|
|
{name, \
|
2013-11-20 20:11:45 +00:00
|
|
|
uint8_t(JS_CHECK_ACCESSOR_FLAGS(flags) | JSPROP_SHARED | JSPROP_GETTER | JSPROP_SETTER), \
|
2014-01-10 17:11:31 +00:00
|
|
|
{ nullptr, JS_CAST_STRING_TO(getterName, const JSJitInfo *) }, \
|
|
|
|
{ nullptr, JS_CAST_STRING_TO(setterName, const JSJitInfo *) } }
|
2014-10-29 19:06:31 +00:00
|
|
|
#define JS_PS_END { nullptr, 0, JSNATIVE_WRAPPER(nullptr), JSNATIVE_WRAPPER(nullptr) }
|
2013-08-21 22:33:11 +00:00
|
|
|
|
2012-07-23 21:01:54 +00:00
|
|
|
/*
|
|
|
|
* To define a native function, set call to a JSNativeWrapper. To define a
|
|
|
|
* self-hosted function, set selfHostedName to the name of a function
|
|
|
|
* compiled during JSRuntime::initSelfHosting.
|
|
|
|
*/
|
1998-03-28 02:44:41 +00:00
|
|
|
struct JSFunctionSpec {
|
|
|
|
const char *name;
|
2012-08-08 05:26:19 +00:00
|
|
|
JSNativeWrapper call;
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-09 03:54:10 +00:00
|
|
|
uint16_t nargs;
|
|
|
|
uint16_t flags;
|
2012-07-23 21:01:54 +00:00
|
|
|
const char *selfHostedName;
|
1998-03-28 02:44:41 +00:00
|
|
|
};
|
|
|
|
|
2007-08-02 04:33:52 +00:00
|
|
|
/*
|
|
|
|
* Terminating sentinel initializer to put at the end of a JSFunctionSpec array
|
|
|
|
* that's passed to JS_DefineFunctions or JS_InitClass.
|
|
|
|
*/
|
2013-10-07 16:42:55 +00:00
|
|
|
#define JS_FS_END JS_FS(nullptr,nullptr,0,0)
|
2007-08-02 04:33:52 +00:00
|
|
|
|
|
|
|
/*
|
2013-09-26 14:11:38 +00:00
|
|
|
* Initializer macros for a JSFunctionSpec array element. JS_FN (whose name pays
|
|
|
|
* homage to the old JSNative/JSFastNative split) simply adds the flag
|
|
|
|
* JSFUN_STUB_GSOPS. JS_FNINFO allows the simple adding of
|
|
|
|
* JSJitInfos. JS_SELF_HOSTED_FN declares a self-hosted function. Finally
|
|
|
|
* JS_FNSPEC has slots for all the fields.
|
2014-07-25 23:50:48 +00:00
|
|
|
*
|
|
|
|
* The _SYM variants allow defining a function with a symbol key rather than a
|
|
|
|
* string key. For example, use JS_SYM_FN(iterator, ...) to define an
|
2015-01-28 04:06:37 +00:00
|
|
|
* @@iterator method.
|
2007-08-02 04:33:52 +00:00
|
|
|
*/
|
2010-08-16 19:35:04 +00:00
|
|
|
#define JS_FS(name,call,nargs,flags) \
|
2013-09-26 14:11:38 +00:00
|
|
|
JS_FNSPEC(name, call, nullptr, nargs, flags, nullptr)
|
2010-08-16 19:35:04 +00:00
|
|
|
#define JS_FN(name,call,nargs,flags) \
|
2013-09-26 14:11:38 +00:00
|
|
|
JS_FNSPEC(name, call, nullptr, nargs, (flags) | JSFUN_STUB_GSOPS, nullptr)
|
2014-07-25 23:50:48 +00:00
|
|
|
#define JS_SYM_FN(name,call,nargs,flags) \
|
|
|
|
JS_SYM_FNSPEC(symbol, call, nullptr, nargs, (flags) | JSFUN_STUB_GSOPS, nullptr)
|
2012-08-08 05:26:19 +00:00
|
|
|
#define JS_FNINFO(name,call,info,nargs,flags) \
|
2013-09-26 14:11:38 +00:00
|
|
|
JS_FNSPEC(name, call, info, nargs, flags, nullptr)
|
|
|
|
#define JS_SELF_HOSTED_FN(name,selfHostedName,nargs,flags) \
|
|
|
|
JS_FNSPEC(name, nullptr, nullptr, nargs, flags, selfHostedName)
|
2014-07-25 23:50:48 +00:00
|
|
|
#define JS_SELF_HOSTED_SYM_FN(symbol, selfHostedName, nargs, flags) \
|
|
|
|
JS_SYM_FNSPEC(symbol, nullptr, nullptr, nargs, flags, selfHostedName)
|
|
|
|
#define JS_SYM_FNSPEC(symbol, call, info, nargs, flags, selfHostedName) \
|
|
|
|
JS_FNSPEC(reinterpret_cast<const char *>( \
|
|
|
|
uint32_t(::JS::SymbolCode::symbol) + 1), \
|
|
|
|
call, info, nargs, flags, selfHostedName)
|
2013-09-26 14:11:38 +00:00
|
|
|
#define JS_FNSPEC(name,call,info,nargs,flags,selfHostedName) \
|
|
|
|
{name, {call, info}, nargs, flags, selfHostedName}
|
2007-08-02 04:33:52 +00:00
|
|
|
|
1998-04-24 00:31:11 +00:00
|
|
|
extern JS_PUBLIC_API(JSObject *)
|
2014-01-29 10:00:40 +00:00
|
|
|
JS_InitClass(JSContext *cx, JS::HandleObject obj, JS::HandleObject parent_proto,
|
2013-09-11 12:49:05 +00:00
|
|
|
const JSClass *clasp, JSNative constructor, unsigned nargs,
|
2013-04-22 20:17:38 +00:00
|
|
|
const JSPropertySpec *ps, const JSFunctionSpec *fs,
|
|
|
|
const JSPropertySpec *static_ps, const JSFunctionSpec *static_fs);
|
1998-03-28 02:44:41 +00:00
|
|
|
|
2012-02-01 03:40:49 +00:00
|
|
|
/*
|
|
|
|
* Set up ctor.prototype = proto and proto.constructor = ctor with the
|
|
|
|
* right property flags.
|
|
|
|
*/
|
2013-08-08 22:53:04 +00:00
|
|
|
extern JS_PUBLIC_API(bool)
|
2014-01-16 17:48:58 +00:00
|
|
|
JS_LinkConstructorAndPrototype(JSContext *cx, JS::Handle<JSObject*> ctor,
|
|
|
|
JS::Handle<JSObject*> proto);
|
2012-02-01 03:40:49 +00:00
|
|
|
|
2013-09-11 12:49:05 +00:00
|
|
|
extern JS_PUBLIC_API(const JSClass *)
|
2013-04-16 01:16:13 +00:00
|
|
|
JS_GetClass(JSObject *obj);
|
1999-11-12 06:03:40 +00:00
|
|
|
|
2013-08-08 22:53:04 +00:00
|
|
|
extern JS_PUBLIC_API(bool)
|
2014-03-20 09:32:37 +00:00
|
|
|
JS_InstanceOf(JSContext *cx, JS::Handle<JSObject*> obj, const JSClass *clasp, JS::CallArgs *args);
|
1998-03-28 02:44:41 +00:00
|
|
|
|
2013-08-08 22:53:04 +00:00
|
|
|
extern JS_PUBLIC_API(bool)
|
2014-01-16 17:48:58 +00:00
|
|
|
JS_HasInstance(JSContext *cx, JS::Handle<JSObject*> obj, JS::Handle<JS::Value> v, bool *bp);
|
2005-05-10 19:53:44 +00:00
|
|
|
|
1998-04-24 00:31:11 +00:00
|
|
|
extern JS_PUBLIC_API(void *)
|
2013-04-16 01:16:13 +00:00
|
|
|
JS_GetPrivate(JSObject *obj);
|
1998-03-28 02:44:41 +00:00
|
|
|
|
2012-02-05 20:07:23 +00:00
|
|
|
extern JS_PUBLIC_API(void)
|
2013-04-16 01:16:13 +00:00
|
|
|
JS_SetPrivate(JSObject *obj, void *data);
|
1998-03-28 02:44:41 +00:00
|
|
|
|
1998-04-24 00:31:11 +00:00
|
|
|
extern JS_PUBLIC_API(void *)
|
2014-03-20 09:32:37 +00:00
|
|
|
JS_GetInstancePrivate(JSContext *cx, JS::Handle<JSObject*> obj, const JSClass *clasp,
|
|
|
|
JS::CallArgs *args);
|
1998-03-28 02:44:41 +00:00
|
|
|
|
2013-08-08 22:53:04 +00:00
|
|
|
extern JS_PUBLIC_API(bool)
|
2014-01-15 10:31:00 +00:00
|
|
|
JS_GetPrototype(JSContext *cx, JS::HandleObject obj, JS::MutableHandleObject protop);
|
1998-03-28 02:44:41 +00:00
|
|
|
|
2013-08-08 22:53:04 +00:00
|
|
|
extern JS_PUBLIC_API(bool)
|
2014-01-15 10:31:00 +00:00
|
|
|
JS_SetPrototype(JSContext *cx, JS::HandleObject obj, JS::HandleObject proto);
|
1998-03-28 02:44:41 +00:00
|
|
|
|
1998-04-24 00:31:11 +00:00
|
|
|
extern JS_PUBLIC_API(JSObject *)
|
2014-01-16 17:48:58 +00:00
|
|
|
JS_GetConstructor(JSContext *cx, JS::Handle<JSObject*> proto);
|
1998-03-28 02:44:41 +00:00
|
|
|
|
2013-03-17 03:36:37 +00:00
|
|
|
namespace JS {
|
|
|
|
|
2013-09-10 17:01:10 +00:00
|
|
|
enum ZoneSpecifier {
|
|
|
|
FreshZone = 0,
|
|
|
|
SystemZone = 1
|
2013-03-17 03:36:37 +00:00
|
|
|
};
|
|
|
|
|
2013-09-10 17:01:10 +00:00
|
|
|
class JS_PUBLIC_API(CompartmentOptions)
|
2013-03-17 03:36:37 +00:00
|
|
|
{
|
2013-09-10 17:01:10 +00:00
|
|
|
public:
|
2013-11-11 20:44:33 +00:00
|
|
|
class Override {
|
|
|
|
public:
|
|
|
|
Override() : mode_(Default) {}
|
|
|
|
|
|
|
|
bool get(bool defaultValue) const {
|
|
|
|
if (mode_ == Default)
|
|
|
|
return defaultValue;
|
|
|
|
return mode_ == ForceTrue;
|
2014-08-18 19:20:39 +00:00
|
|
|
}
|
2013-11-11 20:44:33 +00:00
|
|
|
|
|
|
|
void set(bool overrideValue) {
|
|
|
|
mode_ = overrideValue ? ForceTrue : ForceFalse;
|
2014-08-18 19:20:39 +00:00
|
|
|
}
|
2013-11-11 20:44:33 +00:00
|
|
|
|
|
|
|
void reset() {
|
|
|
|
mode_ = Default;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
enum Mode {
|
|
|
|
Default,
|
|
|
|
ForceTrue,
|
|
|
|
ForceFalse
|
|
|
|
};
|
|
|
|
|
|
|
|
Mode mode_;
|
|
|
|
};
|
2013-06-29 15:11:17 +00:00
|
|
|
|
2013-09-10 17:01:10 +00:00
|
|
|
explicit CompartmentOptions()
|
|
|
|
: version_(JSVERSION_UNKNOWN)
|
2013-11-11 20:44:33 +00:00
|
|
|
, invisibleToDebugger_(false)
|
2014-01-03 10:30:51 +00:00
|
|
|
, mergeable_(false)
|
2014-04-22 21:08:27 +00:00
|
|
|
, discardSource_(false)
|
2014-07-15 16:04:20 +00:00
|
|
|
, cloneSingletons_(false)
|
2014-04-04 23:58:08 +00:00
|
|
|
, traceGlobal_(nullptr)
|
2014-01-23 14:43:28 +00:00
|
|
|
, singletonsAsTemplates_(true)
|
2014-06-21 18:54:36 +00:00
|
|
|
, addonId_(nullptr)
|
2014-09-22 07:43:36 +00:00
|
|
|
, preserveJitCode_(false)
|
2013-09-10 17:01:10 +00:00
|
|
|
{
|
|
|
|
zone_.spec = JS::FreshZone;
|
|
|
|
}
|
2013-06-29 15:11:17 +00:00
|
|
|
|
2013-11-11 20:44:33 +00:00
|
|
|
JSVersion version() const { return version_; }
|
2013-09-10 17:01:10 +00:00
|
|
|
CompartmentOptions &setVersion(JSVersion aVersion) {
|
|
|
|
MOZ_ASSERT(aVersion != JSVERSION_UNKNOWN);
|
|
|
|
version_ = aVersion;
|
2013-07-03 05:30:37 +00:00
|
|
|
return *this;
|
|
|
|
}
|
2013-08-02 01:38:45 +00:00
|
|
|
|
|
|
|
// Certain scopes (i.e. XBL compilation scopes) are implementation details
|
|
|
|
// of the embedding, and references to them should never leak out to script.
|
|
|
|
// This flag causes the this compartment to skip firing onNewGlobalObject
|
|
|
|
// and makes addDebuggee a no-op for this global.
|
2014-01-03 10:30:51 +00:00
|
|
|
bool invisibleToDebugger() const { return invisibleToDebugger_; }
|
2013-11-11 20:44:33 +00:00
|
|
|
CompartmentOptions &setInvisibleToDebugger(bool flag) {
|
|
|
|
invisibleToDebugger_ = flag;
|
2013-08-02 01:38:45 +00:00
|
|
|
return *this;
|
|
|
|
}
|
2013-09-10 17:01:10 +00:00
|
|
|
|
2014-01-03 10:30:51 +00:00
|
|
|
// Compartments used for off-thread compilation have their contents merged
|
|
|
|
// into a target compartment when the compilation is finished. This is only
|
|
|
|
// allowed if this flag is set. The invisibleToDebugger flag must also be
|
|
|
|
// set for such compartments.
|
|
|
|
bool mergeable() const { return mergeable_; }
|
|
|
|
CompartmentOptions &setMergeable(bool flag) {
|
|
|
|
mergeable_ = flag;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2014-04-22 21:08:27 +00:00
|
|
|
// For certain globals, we know enough about the code that will run in them
|
|
|
|
// that we can discard script source entirely.
|
|
|
|
bool discardSource() const { return discardSource_; }
|
|
|
|
CompartmentOptions &setDiscardSource(bool flag) {
|
|
|
|
discardSource_ = flag;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2014-07-15 16:04:20 +00:00
|
|
|
bool cloneSingletons() const { return cloneSingletons_; }
|
|
|
|
CompartmentOptions &setCloneSingletons(bool flag) {
|
|
|
|
cloneSingletons_ = flag;
|
|
|
|
return *this;
|
|
|
|
}
|
2014-01-23 14:43:28 +00:00
|
|
|
|
2014-07-30 04:00:37 +00:00
|
|
|
bool extraWarnings(JSRuntime *rt) const;
|
|
|
|
bool extraWarnings(JSContext *cx) const;
|
|
|
|
Override &extraWarningsOverride() { return extraWarningsOverride_; }
|
|
|
|
|
2013-09-10 17:01:10 +00:00
|
|
|
void *zonePointer() const {
|
2014-10-01 17:17:51 +00:00
|
|
|
MOZ_ASSERT(uintptr_t(zone_.pointer) > uintptr_t(JS::SystemZone));
|
2013-09-10 17:01:10 +00:00
|
|
|
return zone_.pointer;
|
|
|
|
}
|
2013-11-11 20:44:33 +00:00
|
|
|
ZoneSpecifier zoneSpecifier() const { return zone_.spec; }
|
|
|
|
CompartmentOptions &setZone(ZoneSpecifier spec);
|
|
|
|
CompartmentOptions &setSameZoneAs(JSObject *obj);
|
|
|
|
|
2014-01-23 14:43:28 +00:00
|
|
|
void setSingletonsAsValues() {
|
|
|
|
singletonsAsTemplates_ = false;
|
|
|
|
}
|
|
|
|
bool getSingletonsAsTemplates() const {
|
|
|
|
return singletonsAsTemplates_;
|
2014-08-18 19:20:39 +00:00
|
|
|
}
|
2014-01-23 14:43:28 +00:00
|
|
|
|
2014-06-21 18:54:36 +00:00
|
|
|
// A null add-on ID means that the compartment is not associated with an
|
|
|
|
// add-on.
|
|
|
|
JSAddonId *addonIdOrNull() const { return addonId_; }
|
|
|
|
CompartmentOptions &setAddonId(JSAddonId *id) {
|
|
|
|
addonId_ = id;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2014-04-04 23:58:08 +00:00
|
|
|
CompartmentOptions &setTrace(JSTraceOp op) {
|
|
|
|
traceGlobal_ = op;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
JSTraceOp getTrace() const {
|
|
|
|
return traceGlobal_;
|
|
|
|
}
|
|
|
|
|
2014-09-22 07:43:36 +00:00
|
|
|
bool preserveJitCode() const { return preserveJitCode_; }
|
|
|
|
CompartmentOptions &setPreserveJitCode(bool flag) {
|
|
|
|
preserveJitCode_ = flag;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2013-11-11 20:44:33 +00:00
|
|
|
private:
|
|
|
|
JSVersion version_;
|
|
|
|
bool invisibleToDebugger_;
|
2014-01-03 10:30:51 +00:00
|
|
|
bool mergeable_;
|
2014-04-22 21:08:27 +00:00
|
|
|
bool discardSource_;
|
2014-07-15 16:04:20 +00:00
|
|
|
bool cloneSingletons_;
|
2014-07-30 04:00:37 +00:00
|
|
|
Override extraWarningsOverride_;
|
2013-11-11 20:44:33 +00:00
|
|
|
union {
|
|
|
|
ZoneSpecifier spec;
|
|
|
|
void *pointer; // js::Zone* is not exposed in the API.
|
|
|
|
} zone_;
|
2014-04-04 23:58:08 +00:00
|
|
|
JSTraceOp traceGlobal_;
|
2014-01-23 14:43:28 +00:00
|
|
|
|
|
|
|
// To XDR singletons, we need to ensure that all singletons are all used as
|
|
|
|
// templates, by making JSOP_OBJECT return a clone of the JSScript
|
|
|
|
// singleton, instead of returning the value which is baked in the JSScript.
|
|
|
|
bool singletonsAsTemplates_;
|
2014-06-21 18:54:36 +00:00
|
|
|
|
|
|
|
JSAddonId *addonId_;
|
2014-09-22 07:43:36 +00:00
|
|
|
bool preserveJitCode_;
|
2013-06-29 15:11:17 +00:00
|
|
|
};
|
|
|
|
|
2013-11-11 20:44:33 +00:00
|
|
|
JS_PUBLIC_API(CompartmentOptions &)
|
|
|
|
CompartmentOptionsRef(JSCompartment *compartment);
|
|
|
|
|
2014-04-22 21:08:27 +00:00
|
|
|
JS_PUBLIC_API(CompartmentOptions &)
|
|
|
|
CompartmentOptionsRef(JSObject *obj);
|
|
|
|
|
2013-11-11 20:44:33 +00:00
|
|
|
JS_PUBLIC_API(CompartmentOptions &)
|
|
|
|
CompartmentOptionsRef(JSContext *cx);
|
|
|
|
|
2013-08-02 01:38:47 +00:00
|
|
|
// During global creation, we fire notifications to callbacks registered
|
|
|
|
// via the Debugger API. These callbacks are arbitrary script, and can touch
|
|
|
|
// the global in arbitrary ways. When that happens, the global should not be
|
|
|
|
// in a half-baked state. But this creates a problem for consumers that need
|
|
|
|
// to set slots on the global to put it in a consistent state.
|
|
|
|
//
|
|
|
|
// This API provides a way for consumers to set slots atomically (immediately
|
|
|
|
// after the global is created), before any debugger hooks are fired. It's
|
|
|
|
// unfortunately on the clunky side, but that's the way the cookie crumbles.
|
|
|
|
//
|
|
|
|
// If callers have no additional state on the global to set up, they may pass
|
|
|
|
// |FireOnNewGlobalHook| to JS_NewGlobalObject, which causes that function to
|
|
|
|
// fire the hook as its final act before returning. Otherwise, callers should
|
|
|
|
// pass |DontFireOnNewGlobalHook|, which means that they are responsible for
|
|
|
|
// invoking JS_FireOnNewGlobalObject upon successfully creating the global. If
|
|
|
|
// an error occurs and the operation aborts, callers should skip firing the
|
|
|
|
// hook. But otherwise, callers must take care to fire the hook exactly once
|
|
|
|
// before compiling any script in the global's scope (we have assertions in
|
|
|
|
// place to enforce this). This lets us be sure that debugger clients never miss
|
|
|
|
// breakpoints.
|
|
|
|
enum OnNewGlobalHookOption {
|
|
|
|
FireOnNewGlobalHook,
|
|
|
|
DontFireOnNewGlobalHook
|
|
|
|
};
|
|
|
|
|
2013-03-17 03:36:37 +00:00
|
|
|
} /* namespace JS */
|
|
|
|
|
2010-06-04 23:32:10 +00:00
|
|
|
extern JS_PUBLIC_API(JSObject *)
|
2013-09-11 12:49:05 +00:00
|
|
|
JS_NewGlobalObject(JSContext *cx, const JSClass *clasp, JSPrincipals *principals,
|
2013-08-02 01:38:47 +00:00
|
|
|
JS::OnNewGlobalHookOption hookOption,
|
2013-06-29 15:11:17 +00:00
|
|
|
const JS::CompartmentOptions &options = JS::CompartmentOptions());
|
2014-04-04 23:58:08 +00:00
|
|
|
/*
|
|
|
|
* Spidermonkey does not have a good way of keeping track of what compartments should be marked on
|
|
|
|
* their own. We can mark the roots unconditionally, but marking GC things only relevant in live
|
|
|
|
* compartments is hard. To mitigate this, we create a static trace hook, installed on each global
|
|
|
|
* object, from which we can be sure the compartment is relevant, and mark it.
|
|
|
|
*
|
|
|
|
* It is still possible to specify custom trace hooks for global object classes. They can be
|
|
|
|
* provided via the CompartmentOptions passed to JS_NewGlobalObject.
|
|
|
|
*/
|
|
|
|
extern JS_PUBLIC_API(void)
|
|
|
|
JS_GlobalObjectTraceHook(JSTracer *trc, JSObject *global);
|
2010-06-23 21:35:10 +00:00
|
|
|
|
2013-08-02 01:38:47 +00:00
|
|
|
extern JS_PUBLIC_API(void)
|
|
|
|
JS_FireOnNewGlobalObject(JSContext *cx, JS::HandleObject global);
|
|
|
|
|
1998-04-24 00:31:11 +00:00
|
|
|
extern JS_PUBLIC_API(JSObject *)
|
2015-02-26 14:40:08 +00:00
|
|
|
JS_NewObject(JSContext *cx, const JSClass *clasp);
|
1998-03-28 02:44:41 +00:00
|
|
|
|
2010-09-21 18:35:30 +00:00
|
|
|
/* Queries the [[Extensible]] property of the object. */
|
2013-08-08 22:53:04 +00:00
|
|
|
extern JS_PUBLIC_API(bool)
|
2014-01-15 10:31:00 +00:00
|
|
|
JS_IsExtensible(JSContext *cx, JS::HandleObject obj, bool *extensible);
|
2010-09-21 18:35:30 +00:00
|
|
|
|
2013-08-08 22:53:04 +00:00
|
|
|
extern JS_PUBLIC_API(bool)
|
2013-04-16 01:16:13 +00:00
|
|
|
JS_IsNative(JSObject *obj);
|
2011-04-08 21:21:08 +00:00
|
|
|
|
2012-02-29 20:23:38 +00:00
|
|
|
extern JS_PUBLIC_API(JSRuntime *)
|
2013-04-16 01:16:13 +00:00
|
|
|
JS_GetObjectRuntime(JSObject *obj);
|
2012-02-29 20:23:38 +00:00
|
|
|
|
2008-02-14 05:10:42 +00:00
|
|
|
/*
|
2015-01-31 15:18:51 +00:00
|
|
|
* Unlike JS_NewObject, JS_NewObjectWithGivenProto does not compute a default proto.
|
|
|
|
* If proto is JS::NullPtr, the JS object will have `null` as [[Prototype]].
|
2008-02-14 05:10:42 +00:00
|
|
|
*/
|
|
|
|
extern JS_PUBLIC_API(JSObject *)
|
2015-02-26 14:40:08 +00:00
|
|
|
JS_NewObjectWithGivenProto(JSContext *cx, const JSClass *clasp, JS::Handle<JSObject*> proto);
|
2008-02-14 05:10:42 +00:00
|
|
|
|
2015-01-24 15:38:08 +00:00
|
|
|
// Creates a new plain object, like `new Object()`, with Object.prototype as [[Prototype]].
|
|
|
|
extern JS_PUBLIC_API(JSObject *)
|
|
|
|
JS_NewPlainObject(JSContext *cx);
|
|
|
|
|
2010-09-21 18:35:29 +00:00
|
|
|
/*
|
|
|
|
* Freeze obj, and all objects it refers to, recursively. This will not recurse
|
|
|
|
* through non-extensible objects, on the assumption that those are already
|
|
|
|
* deep-frozen.
|
|
|
|
*/
|
2013-08-08 22:53:04 +00:00
|
|
|
extern JS_PUBLIC_API(bool)
|
2014-01-17 18:08:51 +00:00
|
|
|
JS_DeepFreezeObject(JSContext *cx, JS::Handle<JSObject*> obj);
|
2010-09-21 18:35:29 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Freezes an object; see ES5's Object.freeze(obj) method.
|
|
|
|
*/
|
2013-08-08 22:53:04 +00:00
|
|
|
extern JS_PUBLIC_API(bool)
|
2014-01-17 18:08:51 +00:00
|
|
|
JS_FreezeObject(JSContext *cx, JS::Handle<JSObject*> obj);
|
2003-03-14 05:24:58 +00:00
|
|
|
|
2014-10-21 18:40:04 +00:00
|
|
|
/*
|
|
|
|
* Attempt to make |obj| non-extensible. If an error occurs while making the
|
|
|
|
* attempt, return false (with a pending exception set, depending upon the
|
2015-02-04 18:01:01 +00:00
|
|
|
* nature of the error). If no error occurs, return true with |result| set
|
2014-10-21 18:40:04 +00:00
|
|
|
* to indicate whether the attempt successfully set the [[Extensible]] property
|
|
|
|
* to false.
|
|
|
|
*/
|
2013-08-08 22:53:04 +00:00
|
|
|
extern JS_PUBLIC_API(bool)
|
2015-02-04 18:01:01 +00:00
|
|
|
JS_PreventExtensions(JSContext *cx, JS::HandleObject obj, JS::ObjectOpResult &result);
|
2013-07-03 07:24:32 +00:00
|
|
|
|
2010-03-17 15:22:13 +00:00
|
|
|
extern JS_PUBLIC_API(JSObject *)
|
2014-04-02 14:28:03 +00:00
|
|
|
JS_New(JSContext *cx, JS::HandleObject ctor, const JS::HandleValueArray& args);
|
2010-03-17 15:22:13 +00:00
|
|
|
|
2014-04-30 09:10:33 +00:00
|
|
|
|
2015-01-30 17:37:07 +00:00
|
|
|
/*** Property descriptors ************************************************************************/
|
2008-10-24 17:09:09 +00:00
|
|
|
|
2009-03-10 22:21:25 +00:00
|
|
|
struct JSPropertyDescriptor {
|
2015-01-30 19:56:15 +00:00
|
|
|
JSObject *obj;
|
|
|
|
unsigned attrs;
|
|
|
|
JSGetterOp getter;
|
|
|
|
JSSetterOp setter;
|
|
|
|
JS::Value value;
|
2012-11-06 01:49:44 +00:00
|
|
|
|
2014-02-21 16:24:26 +00:00
|
|
|
JSPropertyDescriptor()
|
|
|
|
: obj(nullptr), attrs(0), getter(nullptr), setter(nullptr), value(JSVAL_VOID)
|
2012-11-06 01:49:44 +00:00
|
|
|
{}
|
2013-04-12 23:34:27 +00:00
|
|
|
|
|
|
|
void trace(JSTracer *trc);
|
2014-06-05 14:38:00 +00:00
|
|
|
|
|
|
|
static js::ThingRootKind rootKind() { return js::THING_ROOT_PROPERTY_DESCRIPTOR; }
|
2013-04-12 23:34:27 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
namespace JS {
|
|
|
|
|
|
|
|
template <typename Outer>
|
|
|
|
class PropertyDescriptorOperations
|
|
|
|
{
|
|
|
|
const JSPropertyDescriptor * desc() const { return static_cast<const Outer*>(this)->extract(); }
|
|
|
|
|
2015-02-15 12:18:30 +00:00
|
|
|
bool has(unsigned bit) const {
|
|
|
|
MOZ_ASSERT(bit != 0);
|
|
|
|
MOZ_ASSERT((bit & (bit - 1)) == 0); // only a single bit
|
|
|
|
return (desc()->attrs & bit) != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool hasAny(unsigned bits) const {
|
|
|
|
return (desc()->attrs & bits) != 0;
|
|
|
|
}
|
|
|
|
|
2013-04-12 23:34:27 +00:00
|
|
|
public:
|
2015-02-13 20:31:27 +00:00
|
|
|
// Descriptors with JSGetterOp/JSSetterOp are considered data
|
|
|
|
// descriptors. It's complicated.
|
2015-02-15 12:18:30 +00:00
|
|
|
bool isAccessorDescriptor() const { return hasAny(JSPROP_GETTER | JSPROP_SETTER); }
|
2015-02-14 00:52:45 +00:00
|
|
|
bool isGenericDescriptor() const {
|
|
|
|
return (desc()->attrs &
|
|
|
|
(JSPROP_GETTER | JSPROP_SETTER | JSPROP_IGNORE_READONLY | JSPROP_IGNORE_VALUE)) ==
|
|
|
|
(JSPROP_IGNORE_READONLY | JSPROP_IGNORE_VALUE);
|
|
|
|
}
|
|
|
|
bool isDataDescriptor() const { return !isAccessorDescriptor() && !isGenericDescriptor(); }
|
|
|
|
|
2015-02-15 12:18:30 +00:00
|
|
|
bool hasConfigurable() const { return !has(JSPROP_IGNORE_PERMANENT); }
|
|
|
|
bool configurable() const { MOZ_ASSERT(hasConfigurable()); return !has(JSPROP_PERMANENT); }
|
2013-04-12 23:34:27 +00:00
|
|
|
|
2015-02-15 12:18:30 +00:00
|
|
|
bool hasEnumerable() const { return !has(JSPROP_IGNORE_ENUMERATE); }
|
|
|
|
bool enumerable() const { MOZ_ASSERT(hasEnumerable()); return has(JSPROP_ENUMERATE); }
|
2014-10-13 21:46:04 +00:00
|
|
|
|
2015-02-15 12:18:30 +00:00
|
|
|
bool hasValue() const { return !isAccessorDescriptor() && !has(JSPROP_IGNORE_VALUE); }
|
|
|
|
JS::HandleValue value() const {
|
|
|
|
return JS::HandleValue::fromMarkedLocation(&desc()->value);
|
2013-08-01 20:55:12 +00:00
|
|
|
}
|
2015-02-15 12:18:30 +00:00
|
|
|
|
|
|
|
bool hasWritable() const { return !isAccessorDescriptor() && !has(JSPROP_IGNORE_READONLY); }
|
|
|
|
bool writable() const { MOZ_ASSERT(hasWritable()); return !has(JSPROP_READONLY); }
|
|
|
|
|
|
|
|
bool hasGetterObject() const { return has(JSPROP_GETTER); }
|
2014-01-15 10:31:00 +00:00
|
|
|
JS::HandleObject getterObject() const {
|
2013-04-12 23:34:27 +00:00
|
|
|
MOZ_ASSERT(hasGetterObject());
|
2014-01-15 10:31:00 +00:00
|
|
|
return JS::HandleObject::fromMarkedLocation(
|
2013-08-01 20:55:12 +00:00
|
|
|
reinterpret_cast<JSObject *const *>(&desc()->getter));
|
2013-04-12 23:34:27 +00:00
|
|
|
}
|
2015-02-15 12:18:30 +00:00
|
|
|
bool hasSetterObject() const { return has(JSPROP_SETTER); }
|
2014-01-15 10:31:00 +00:00
|
|
|
JS::HandleObject setterObject() const {
|
2013-04-12 23:34:27 +00:00
|
|
|
MOZ_ASSERT(hasSetterObject());
|
2014-01-15 10:31:00 +00:00
|
|
|
return JS::HandleObject::fromMarkedLocation(
|
2013-08-01 20:55:12 +00:00
|
|
|
reinterpret_cast<JSObject *const *>(&desc()->setter));
|
|
|
|
}
|
2015-02-15 12:18:30 +00:00
|
|
|
|
|
|
|
bool hasGetterOrSetter() const { return desc()->getter || desc()->setter; }
|
|
|
|
bool isShared() const { return has(JSPROP_SHARED); }
|
|
|
|
|
|
|
|
JS::HandleObject object() const {
|
|
|
|
return JS::HandleObject::fromMarkedLocation(&desc()->obj);
|
2013-04-30 17:29:40 +00:00
|
|
|
}
|
2015-02-15 12:18:30 +00:00
|
|
|
unsigned attributes() const { return desc()->attrs; }
|
|
|
|
JSGetterOp getter() const { return desc()->getter; }
|
|
|
|
JSSetterOp setter() const { return desc()->setter; }
|
2013-04-30 17:29:40 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
template <typename Outer>
|
|
|
|
class MutablePropertyDescriptorOperations : public PropertyDescriptorOperations<Outer>
|
|
|
|
{
|
|
|
|
JSPropertyDescriptor * desc() { return static_cast<Outer*>(this)->extractMutable(); }
|
|
|
|
|
|
|
|
public:
|
2013-08-12 11:09:14 +00:00
|
|
|
void clear() {
|
2013-10-07 16:42:55 +00:00
|
|
|
object().set(nullptr);
|
2013-08-12 11:09:14 +00:00
|
|
|
setAttributes(0);
|
2013-10-07 16:42:55 +00:00
|
|
|
setGetter(nullptr);
|
|
|
|
setSetter(nullptr);
|
2013-08-12 11:09:14 +00:00
|
|
|
value().setUndefined();
|
|
|
|
}
|
|
|
|
|
2014-06-06 05:32:37 +00:00
|
|
|
void assign(JSPropertyDescriptor &other) {
|
|
|
|
object().set(other.obj);
|
|
|
|
setAttributes(other.attrs);
|
|
|
|
setGetter(other.getter);
|
|
|
|
setSetter(other.setter);
|
|
|
|
value().set(other.value);
|
|
|
|
}
|
|
|
|
|
2015-02-13 20:31:27 +00:00
|
|
|
void setDataDescriptor(HandleValue v, unsigned attrs) {
|
|
|
|
MOZ_ASSERT((attrs & ~(JSPROP_ENUMERATE |
|
|
|
|
JSPROP_PERMANENT |
|
|
|
|
JSPROP_READONLY |
|
|
|
|
JSPROP_IGNORE_ENUMERATE |
|
|
|
|
JSPROP_IGNORE_PERMANENT |
|
|
|
|
JSPROP_IGNORE_READONLY)) == 0);
|
|
|
|
object().set(nullptr);
|
|
|
|
setAttributes(attrs);
|
|
|
|
setGetter(nullptr);
|
|
|
|
setSetter(nullptr);
|
|
|
|
value().set(v);
|
|
|
|
}
|
|
|
|
|
2014-01-15 10:31:00 +00:00
|
|
|
JS::MutableHandleObject object() {
|
|
|
|
return JS::MutableHandleObject::fromMarkedLocation(&desc()->obj);
|
2013-04-30 17:29:40 +00:00
|
|
|
}
|
|
|
|
unsigned &attributesRef() { return desc()->attrs; }
|
2015-01-30 19:56:15 +00:00
|
|
|
JSGetterOp &getter() { return desc()->getter; }
|
|
|
|
JSSetterOp &setter() { return desc()->setter; }
|
2014-01-15 10:31:00 +00:00
|
|
|
JS::MutableHandleValue value() {
|
|
|
|
return JS::MutableHandleValue::fromMarkedLocation(&desc()->value);
|
2013-04-12 23:34:27 +00:00
|
|
|
}
|
2015-02-13 20:31:27 +00:00
|
|
|
void setValue(JS::HandleValue v) {
|
|
|
|
MOZ_ASSERT(!(desc()->attrs & (JSPROP_GETTER | JSPROP_SETTER)));
|
|
|
|
attributesRef() &= ~JSPROP_IGNORE_VALUE;
|
|
|
|
value().set(v);
|
|
|
|
}
|
2013-04-12 23:34:27 +00:00
|
|
|
|
2013-04-30 17:29:40 +00:00
|
|
|
void setEnumerable() { desc()->attrs |= JSPROP_ENUMERATE; }
|
2013-04-12 23:34:27 +00:00
|
|
|
void setAttributes(unsigned attrs) { desc()->attrs = attrs; }
|
2013-04-30 17:29:40 +00:00
|
|
|
|
2015-01-30 19:56:15 +00:00
|
|
|
void setGetter(JSGetterOp op) {
|
2014-11-22 18:23:39 +00:00
|
|
|
MOZ_ASSERT(op != JS_PropertyStub);
|
|
|
|
desc()->getter = op;
|
|
|
|
}
|
2015-01-30 19:56:15 +00:00
|
|
|
void setSetter(JSSetterOp op) {
|
2014-11-22 18:23:39 +00:00
|
|
|
MOZ_ASSERT(op != JS_StrictPropertyStub);
|
|
|
|
desc()->setter = op;
|
|
|
|
}
|
2015-01-30 19:56:15 +00:00
|
|
|
void setGetterObject(JSObject *obj) { desc()->getter = reinterpret_cast<JSGetterOp>(obj); }
|
|
|
|
void setSetterObject(JSObject *obj) { desc()->setter = reinterpret_cast<JSSetterOp>(obj); }
|
2014-07-15 05:10:05 +00:00
|
|
|
|
|
|
|
JS::MutableHandleObject getterObject() {
|
|
|
|
MOZ_ASSERT(this->hasGetterObject());
|
|
|
|
return JS::MutableHandleObject::fromMarkedLocation(
|
|
|
|
reinterpret_cast<JSObject **>(&desc()->getter));
|
|
|
|
}
|
|
|
|
JS::MutableHandleObject setterObject() {
|
|
|
|
MOZ_ASSERT(this->hasSetterObject());
|
|
|
|
return JS::MutableHandleObject::fromMarkedLocation(
|
|
|
|
reinterpret_cast<JSObject **>(&desc()->setter));
|
|
|
|
}
|
2009-03-10 22:21:25 +00:00
|
|
|
};
|
|
|
|
|
2013-04-12 23:34:27 +00:00
|
|
|
} /* namespace JS */
|
|
|
|
|
|
|
|
namespace js {
|
|
|
|
|
|
|
|
template <>
|
2013-06-19 10:32:26 +00:00
|
|
|
struct GCMethods<JSPropertyDescriptor> {
|
2013-04-12 23:34:27 +00:00
|
|
|
static JSPropertyDescriptor initial() { return JSPropertyDescriptor(); }
|
|
|
|
};
|
|
|
|
|
|
|
|
template <>
|
|
|
|
class RootedBase<JSPropertyDescriptor>
|
2013-04-30 17:29:40 +00:00
|
|
|
: public JS::MutablePropertyDescriptorOperations<JS::Rooted<JSPropertyDescriptor> >
|
2013-04-12 23:34:27 +00:00
|
|
|
{
|
|
|
|
friend class JS::PropertyDescriptorOperations<JS::Rooted<JSPropertyDescriptor> >;
|
2013-04-30 17:29:40 +00:00
|
|
|
friend class JS::MutablePropertyDescriptorOperations<JS::Rooted<JSPropertyDescriptor> >;
|
2013-04-12 23:34:27 +00:00
|
|
|
const JSPropertyDescriptor *extract() const {
|
|
|
|
return static_cast<const JS::Rooted<JSPropertyDescriptor>*>(this)->address();
|
|
|
|
}
|
2013-04-30 17:29:40 +00:00
|
|
|
JSPropertyDescriptor *extractMutable() {
|
2013-04-12 23:34:27 +00:00
|
|
|
return static_cast<JS::Rooted<JSPropertyDescriptor>*>(this)->address();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template <>
|
|
|
|
class HandleBase<JSPropertyDescriptor>
|
|
|
|
: public JS::PropertyDescriptorOperations<JS::Handle<JSPropertyDescriptor> >
|
|
|
|
{
|
2013-04-15 17:33:27 +00:00
|
|
|
friend class JS::PropertyDescriptorOperations<JS::Handle<JSPropertyDescriptor> >;
|
2013-04-12 23:34:27 +00:00
|
|
|
const JSPropertyDescriptor *extract() const {
|
|
|
|
return static_cast<const JS::Handle<JSPropertyDescriptor>*>(this)->address();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template <>
|
|
|
|
class MutableHandleBase<JSPropertyDescriptor>
|
2013-04-30 17:29:40 +00:00
|
|
|
: public JS::MutablePropertyDescriptorOperations<JS::MutableHandle<JSPropertyDescriptor> >
|
2013-04-12 23:34:27 +00:00
|
|
|
{
|
2013-04-15 17:33:27 +00:00
|
|
|
friend class JS::PropertyDescriptorOperations<JS::MutableHandle<JSPropertyDescriptor> >;
|
2013-04-30 17:29:40 +00:00
|
|
|
friend class JS::MutablePropertyDescriptorOperations<JS::MutableHandle<JSPropertyDescriptor> >;
|
2013-04-12 23:34:27 +00:00
|
|
|
const JSPropertyDescriptor *extract() const {
|
|
|
|
return static_cast<const JS::MutableHandle<JSPropertyDescriptor>*>(this)->address();
|
|
|
|
}
|
2013-04-30 17:29:40 +00:00
|
|
|
JSPropertyDescriptor *extractMutable() {
|
2013-04-12 23:34:27 +00:00
|
|
|
return static_cast<JS::MutableHandle<JSPropertyDescriptor>*>(this)->address();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
} /* namespace js */
|
|
|
|
|
2014-07-15 05:10:05 +00:00
|
|
|
namespace JS {
|
|
|
|
|
|
|
|
extern JS_PUBLIC_API(bool)
|
2015-02-15 08:49:42 +00:00
|
|
|
ObjectToCompletePropertyDescriptor(JSContext *cx,
|
|
|
|
JS::HandleObject obj,
|
|
|
|
JS::HandleValue descriptor,
|
|
|
|
JS::MutableHandle<JSPropertyDescriptor> desc);
|
2014-07-15 05:10:05 +00:00
|
|
|
|
|
|
|
} // namespace JS
|
|
|
|
|
2015-01-30 17:37:07 +00:00
|
|
|
|
|
|
|
/*** [[DefineOwnProperty]] and variations ********************************************************/
|
|
|
|
|
|
|
|
extern JS_PUBLIC_API(bool)
|
|
|
|
JS_DefineProperty(JSContext *cx, JS::HandleObject obj, const char *name, JS::HandleValue value,
|
|
|
|
unsigned attrs,
|
|
|
|
JSNative getter = nullptr, JSNative setter = nullptr);
|
|
|
|
|
|
|
|
extern JS_PUBLIC_API(bool)
|
|
|
|
JS_DefineProperty(JSContext *cx, JS::HandleObject obj, const char *name, JS::HandleObject value,
|
|
|
|
unsigned attrs,
|
|
|
|
JSNative getter = nullptr, JSNative setter = nullptr);
|
|
|
|
|
|
|
|
extern JS_PUBLIC_API(bool)
|
|
|
|
JS_DefineProperty(JSContext *cx, JS::HandleObject obj, const char *name, JS::HandleString value,
|
|
|
|
unsigned attrs,
|
|
|
|
JSNative getter = nullptr, JSNative setter = nullptr);
|
|
|
|
|
|
|
|
extern JS_PUBLIC_API(bool)
|
|
|
|
JS_DefineProperty(JSContext *cx, JS::HandleObject obj, const char *name, int32_t value,
|
|
|
|
unsigned attrs,
|
|
|
|
JSNative getter = nullptr, JSNative setter = nullptr);
|
|
|
|
|
|
|
|
extern JS_PUBLIC_API(bool)
|
|
|
|
JS_DefineProperty(JSContext *cx, JS::HandleObject obj, const char *name, uint32_t value,
|
|
|
|
unsigned attrs,
|
|
|
|
JSNative getter = nullptr, JSNative setter = nullptr);
|
|
|
|
|
|
|
|
extern JS_PUBLIC_API(bool)
|
|
|
|
JS_DefineProperty(JSContext *cx, JS::HandleObject obj, const char *name, double value,
|
|
|
|
unsigned attrs,
|
|
|
|
JSNative getter = nullptr, JSNative setter = nullptr);
|
|
|
|
|
|
|
|
extern JS_PUBLIC_API(bool)
|
|
|
|
JS_DefinePropertyById(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::HandleValue value,
|
|
|
|
unsigned attrs,
|
|
|
|
JSNative getter = nullptr, JSNative setter = nullptr);
|
|
|
|
|
|
|
|
extern JS_PUBLIC_API(bool)
|
|
|
|
JS_DefinePropertyById(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::HandleObject value,
|
|
|
|
unsigned attrs,
|
|
|
|
JSNative getter = nullptr, JSNative setter = nullptr);
|
|
|
|
|
|
|
|
extern JS_PUBLIC_API(bool)
|
|
|
|
JS_DefinePropertyById(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::HandleString value,
|
|
|
|
unsigned attrs,
|
|
|
|
JSNative getter = nullptr, JSNative setter = nullptr);
|
|
|
|
|
|
|
|
extern JS_PUBLIC_API(bool)
|
|
|
|
JS_DefinePropertyById(JSContext *cx, JS::HandleObject obj, JS::HandleId id, int32_t value,
|
|
|
|
unsigned attrs,
|
|
|
|
JSNative getter = nullptr, JSNative setter = nullptr);
|
|
|
|
|
|
|
|
extern JS_PUBLIC_API(bool)
|
|
|
|
JS_DefinePropertyById(JSContext *cx, JS::HandleObject obj, JS::HandleId id, uint32_t value,
|
|
|
|
unsigned attrs,
|
|
|
|
JSNative getter = nullptr, JSNative setter = nullptr);
|
|
|
|
|
|
|
|
extern JS_PUBLIC_API(bool)
|
|
|
|
JS_DefinePropertyById(JSContext *cx, JS::HandleObject obj, JS::HandleId id, double value,
|
|
|
|
unsigned attrs,
|
|
|
|
JSNative getter = nullptr, JSNative setter = nullptr);
|
|
|
|
|
|
|
|
extern JS_PUBLIC_API(bool)
|
|
|
|
JS_DefinePropertyById(JSContext *cx, JS::HandleObject obj, JS::HandleId id,
|
|
|
|
JS::Handle<JSPropertyDescriptor> desc,
|
|
|
|
JS::ObjectOpResult &result);
|
|
|
|
|
|
|
|
extern JS_PUBLIC_API(bool)
|
|
|
|
JS_DefinePropertyById(JSContext *cx, JS::HandleObject obj, JS::HandleId id,
|
|
|
|
JS::Handle<JSPropertyDescriptor> desc);
|
|
|
|
|
|
|
|
extern JS_PUBLIC_API(JSObject *)
|
|
|
|
JS_DefineObject(JSContext *cx, JS::HandleObject obj, const char *name,
|
|
|
|
const JSClass *clasp = nullptr, unsigned attrs = 0);
|
|
|
|
|
|
|
|
extern JS_PUBLIC_API(bool)
|
|
|
|
JS_DefineConstDoubles(JSContext *cx, JS::HandleObject obj, const JSConstDoubleSpec *cds);
|
|
|
|
|
|
|
|
extern JS_PUBLIC_API(bool)
|
|
|
|
JS_DefineConstIntegers(JSContext *cx, JS::HandleObject obj, const JSConstIntegerSpec *cis);
|
|
|
|
|
|
|
|
extern JS_PUBLIC_API(bool)
|
|
|
|
JS_DefineProperties(JSContext *cx, JS::HandleObject obj, const JSPropertySpec *ps);
|
|
|
|
|
|
|
|
|
|
|
|
/* * */
|
|
|
|
|
|
|
|
extern JS_PUBLIC_API(bool)
|
|
|
|
JS_AlreadyHasOwnProperty(JSContext *cx, JS::HandleObject obj, const char *name,
|
|
|
|
bool *foundp);
|
|
|
|
|
|
|
|
extern JS_PUBLIC_API(bool)
|
|
|
|
JS_AlreadyHasOwnPropertyById(JSContext *cx, JS::HandleObject obj, JS::HandleId id,
|
|
|
|
bool *foundp);
|
|
|
|
|
|
|
|
extern JS_PUBLIC_API(bool)
|
|
|
|
JS_HasProperty(JSContext *cx, JS::HandleObject obj, const char *name, bool *foundp);
|
|
|
|
|
|
|
|
extern JS_PUBLIC_API(bool)
|
|
|
|
JS_HasPropertyById(JSContext *cx, JS::HandleObject obj, JS::HandleId id, bool *foundp);
|
|
|
|
|
|
|
|
|
2013-09-06 17:05:28 +00:00
|
|
|
extern JS_PUBLIC_API(bool)
|
2014-03-17 16:17:58 +00:00
|
|
|
JS_GetOwnPropertyDescriptorById(JSContext *cx, JS::HandleObject obj, JS::HandleId id,
|
2014-04-25 21:11:01 +00:00
|
|
|
JS::MutableHandle<JSPropertyDescriptor> desc);
|
2013-09-06 17:05:28 +00:00
|
|
|
|
|
|
|
extern JS_PUBLIC_API(bool)
|
2014-04-25 21:11:01 +00:00
|
|
|
JS_GetOwnPropertyDescriptor(JSContext *cx, JS::HandleObject obj, const char *name,
|
2013-09-06 17:05:28 +00:00
|
|
|
JS::MutableHandle<JSPropertyDescriptor> desc);
|
|
|
|
|
2015-03-13 19:05:57 +00:00
|
|
|
extern JS_PUBLIC_API(bool)
|
|
|
|
JS_GetOwnUCPropertyDescriptor(JSContext *cx, JS::HandleObject obj, const char16_t *name,
|
|
|
|
JS::MutableHandle<JSPropertyDescriptor> desc);
|
|
|
|
|
2009-03-10 22:21:25 +00:00
|
|
|
/*
|
2013-09-06 17:05:28 +00:00
|
|
|
* Like JS_GetOwnPropertyDescriptorById but will return a property on
|
|
|
|
* an object on the prototype chain (returned in desc->obj). If desc->obj is null,
|
2009-03-10 22:21:25 +00:00
|
|
|
* then this property was not found on the prototype chain.
|
|
|
|
*/
|
2013-08-08 22:53:04 +00:00
|
|
|
extern JS_PUBLIC_API(bool)
|
2014-04-25 21:11:01 +00:00
|
|
|
JS_GetPropertyDescriptorById(JSContext *cx, JS::HandleObject obj, JS::HandleId id,
|
2013-08-12 11:09:14 +00:00
|
|
|
JS::MutableHandle<JSPropertyDescriptor> desc);
|
2009-03-10 22:21:25 +00:00
|
|
|
|
2013-08-08 22:53:04 +00:00
|
|
|
extern JS_PUBLIC_API(bool)
|
2014-04-25 21:11:01 +00:00
|
|
|
JS_GetPropertyDescriptor(JSContext *cx, JS::HandleObject obj, const char *name,
|
2013-09-06 17:05:28 +00:00
|
|
|
JS::MutableHandle<JSPropertyDescriptor> desc);
|
2010-03-24 19:36:42 +00:00
|
|
|
|
2013-08-08 22:53:04 +00:00
|
|
|
extern JS_PUBLIC_API(bool)
|
2014-01-31 09:55:20 +00:00
|
|
|
JS_GetProperty(JSContext *cx, JS::HandleObject obj, const char *name, JS::MutableHandleValue vp);
|
1998-03-28 02:44:41 +00:00
|
|
|
|
2013-08-08 22:53:04 +00:00
|
|
|
extern JS_PUBLIC_API(bool)
|
2014-01-31 09:55:20 +00:00
|
|
|
JS_GetPropertyById(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::MutableHandleValue vp);
|
2008-10-24 17:09:09 +00:00
|
|
|
|
2013-08-08 22:53:04 +00:00
|
|
|
extern JS_PUBLIC_API(bool)
|
2014-01-24 23:01:47 +00:00
|
|
|
JS_ForwardGetPropertyTo(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::HandleObject onBehalfOf,
|
2014-01-15 10:31:00 +00:00
|
|
|
JS::MutableHandleValue vp);
|
2011-11-04 16:18:38 +00:00
|
|
|
|
2013-08-08 22:53:04 +00:00
|
|
|
extern JS_PUBLIC_API(bool)
|
2014-01-25 09:29:12 +00:00
|
|
|
JS_SetProperty(JSContext *cx, JS::HandleObject obj, const char *name, JS::HandleValue v);
|
1998-03-28 02:44:41 +00:00
|
|
|
|
2013-08-08 22:53:04 +00:00
|
|
|
extern JS_PUBLIC_API(bool)
|
2014-01-25 09:29:12 +00:00
|
|
|
JS_SetPropertyById(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::HandleValue v);
|
2008-10-24 17:09:09 +00:00
|
|
|
|
2014-12-26 21:36:06 +00:00
|
|
|
extern JS_PUBLIC_API(bool)
|
2015-02-04 01:51:40 +00:00
|
|
|
JS_ForwardSetPropertyTo(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::HandleValue v,
|
|
|
|
JS::HandleValue receiver, JS::ObjectOpResult &result);
|
2014-12-26 21:36:06 +00:00
|
|
|
|
2013-08-08 22:53:04 +00:00
|
|
|
extern JS_PUBLIC_API(bool)
|
2014-01-22 11:28:06 +00:00
|
|
|
JS_DeleteProperty(JSContext *cx, JS::HandleObject obj, const char *name);
|
1998-03-28 02:44:41 +00:00
|
|
|
|
2013-08-08 22:53:04 +00:00
|
|
|
extern JS_PUBLIC_API(bool)
|
2015-02-04 16:20:04 +00:00
|
|
|
JS_DeleteProperty(JSContext *cx, JS::HandleObject obj, const char *name,
|
|
|
|
JS::ObjectOpResult &result);
|
1998-04-24 00:31:11 +00:00
|
|
|
|
2013-08-08 22:53:04 +00:00
|
|
|
extern JS_PUBLIC_API(bool)
|
2014-01-22 11:28:06 +00:00
|
|
|
JS_DeletePropertyById(JSContext *cx, JS::HandleObject obj, jsid id);
|
2008-10-24 17:09:09 +00:00
|
|
|
|
2013-08-08 22:53:04 +00:00
|
|
|
extern JS_PUBLIC_API(bool)
|
2015-02-04 16:20:04 +00:00
|
|
|
JS_DeletePropertyById(JSContext *cx, JS::HandleObject obj, JS::HandleId id,
|
|
|
|
JS::ObjectOpResult &result);
|
2008-10-24 17:09:09 +00:00
|
|
|
|
2013-08-08 22:53:04 +00:00
|
|
|
extern JS_PUBLIC_API(bool)
|
2014-07-22 04:43:21 +00:00
|
|
|
JS_DefineUCProperty(JSContext *cx, JS::HandleObject obj, const char16_t *name, size_t namelen,
|
2014-04-30 09:10:33 +00:00
|
|
|
JS::HandleValue value, unsigned attrs,
|
2014-10-29 19:06:31 +00:00
|
|
|
JSNative getter = nullptr, JSNative setter = nullptr);
|
2014-04-30 09:10:33 +00:00
|
|
|
|
|
|
|
extern JS_PUBLIC_API(bool)
|
2014-07-22 04:43:21 +00:00
|
|
|
JS_DefineUCProperty(JSContext *cx, JS::HandleObject obj, const char16_t *name, size_t namelen,
|
2014-04-30 09:10:33 +00:00
|
|
|
JS::HandleObject value, unsigned attrs,
|
2014-10-29 19:06:31 +00:00
|
|
|
JSNative getter = nullptr, JSNative setter = nullptr);
|
2014-04-30 09:10:33 +00:00
|
|
|
|
|
|
|
extern JS_PUBLIC_API(bool)
|
2014-07-22 04:43:21 +00:00
|
|
|
JS_DefineUCProperty(JSContext *cx, JS::HandleObject obj, const char16_t *name, size_t namelen,
|
2014-04-30 09:10:33 +00:00
|
|
|
JS::HandleString value, unsigned attrs,
|
2014-10-29 19:06:31 +00:00
|
|
|
JSNative getter = nullptr, JSNative setter = nullptr);
|
2014-04-30 09:10:33 +00:00
|
|
|
|
|
|
|
extern JS_PUBLIC_API(bool)
|
2014-07-22 04:43:21 +00:00
|
|
|
JS_DefineUCProperty(JSContext *cx, JS::HandleObject obj, const char16_t *name, size_t namelen,
|
2014-04-30 09:10:33 +00:00
|
|
|
int32_t value, unsigned attrs,
|
2014-10-29 19:06:31 +00:00
|
|
|
JSNative getter = nullptr, JSNative setter = nullptr);
|
2014-04-30 09:10:33 +00:00
|
|
|
|
|
|
|
extern JS_PUBLIC_API(bool)
|
2014-07-22 04:43:21 +00:00
|
|
|
JS_DefineUCProperty(JSContext *cx, JS::HandleObject obj, const char16_t *name, size_t namelen,
|
2014-04-30 09:10:33 +00:00
|
|
|
uint32_t value, unsigned attrs,
|
2014-10-29 19:06:31 +00:00
|
|
|
JSNative getter = nullptr, JSNative setter = nullptr);
|
2014-04-30 09:10:33 +00:00
|
|
|
|
|
|
|
extern JS_PUBLIC_API(bool)
|
2014-07-22 04:43:21 +00:00
|
|
|
JS_DefineUCProperty(JSContext *cx, JS::HandleObject obj, const char16_t *name, size_t namelen,
|
2014-04-30 09:10:33 +00:00
|
|
|
double value, unsigned attrs,
|
2014-10-29 19:06:31 +00:00
|
|
|
JSNative getter = nullptr, JSNative setter = nullptr);
|
1998-04-24 00:31:11 +00:00
|
|
|
|
2015-01-30 17:37:07 +00:00
|
|
|
extern JS_PUBLIC_API(bool)
|
|
|
|
JS_DefineUCProperty(JSContext *cx, JS::HandleObject obj, const char16_t *name, size_t namelen,
|
|
|
|
JS::Handle<JSPropertyDescriptor> desc,
|
|
|
|
JS::ObjectOpResult &result);
|
|
|
|
|
|
|
|
extern JS_PUBLIC_API(bool)
|
|
|
|
JS_DefineUCProperty(JSContext *cx, JS::HandleObject obj, const char16_t *name, size_t namelen,
|
|
|
|
JS::Handle<JSPropertyDescriptor> desc);
|
|
|
|
|
2013-08-08 22:53:04 +00:00
|
|
|
extern JS_PUBLIC_API(bool)
|
2014-07-22 04:43:21 +00:00
|
|
|
JS_AlreadyHasOwnUCProperty(JSContext *cx, JS::HandleObject obj, const char16_t *name,
|
2013-08-08 22:53:04 +00:00
|
|
|
size_t namelen, bool *foundp);
|
2007-11-13 08:28:47 +00:00
|
|
|
|
2013-08-08 22:53:04 +00:00
|
|
|
extern JS_PUBLIC_API(bool)
|
2014-01-22 11:28:06 +00:00
|
|
|
JS_HasUCProperty(JSContext *cx, JS::HandleObject obj,
|
2014-07-22 04:43:21 +00:00
|
|
|
const char16_t *name, size_t namelen,
|
2013-08-08 22:53:04 +00:00
|
|
|
bool *vp);
|
2004-07-17 02:39:55 +00:00
|
|
|
|
2013-08-08 22:53:04 +00:00
|
|
|
extern JS_PUBLIC_API(bool)
|
2014-01-31 09:55:20 +00:00
|
|
|
JS_GetUCProperty(JSContext *cx, JS::HandleObject obj,
|
2014-07-22 04:43:21 +00:00
|
|
|
const char16_t *name, size_t namelen,
|
2014-01-15 10:31:00 +00:00
|
|
|
JS::MutableHandleValue vp);
|
1998-04-24 00:31:11 +00:00
|
|
|
|
2013-08-08 22:53:04 +00:00
|
|
|
extern JS_PUBLIC_API(bool)
|
2014-01-25 09:29:12 +00:00
|
|
|
JS_SetUCProperty(JSContext *cx, JS::HandleObject obj,
|
2014-07-22 04:43:21 +00:00
|
|
|
const char16_t *name, size_t namelen,
|
2014-01-15 10:31:00 +00:00
|
|
|
JS::HandleValue v);
|
1998-04-24 00:31:11 +00:00
|
|
|
|
2013-08-08 22:53:04 +00:00
|
|
|
extern JS_PUBLIC_API(bool)
|
2015-02-04 16:20:04 +00:00
|
|
|
JS_DeleteUCProperty(JSContext *cx, JS::HandleObject obj, const char16_t *name, size_t namelen,
|
|
|
|
JS::ObjectOpResult &result);
|
1998-04-24 00:31:11 +00:00
|
|
|
|
|
|
|
extern JS_PUBLIC_API(JSObject *)
|
2014-02-12 10:50:46 +00:00
|
|
|
JS_NewArrayObject(JSContext *cx, const JS::HandleValueArray& contents);
|
|
|
|
|
|
|
|
extern JS_PUBLIC_API(JSObject *)
|
|
|
|
JS_NewArrayObject(JSContext *cx, size_t length);
|
1998-03-28 02:44:41 +00:00
|
|
|
|
2013-08-08 22:53:04 +00:00
|
|
|
extern JS_PUBLIC_API(bool)
|
2014-01-29 10:00:40 +00:00
|
|
|
JS_IsArrayObject(JSContext *cx, JS::HandleValue value);
|
|
|
|
|
|
|
|
extern JS_PUBLIC_API(bool)
|
|
|
|
JS_IsArrayObject(JSContext *cx, JS::HandleObject obj);
|
1998-03-28 02:44:41 +00:00
|
|
|
|
2013-08-08 22:53:04 +00:00
|
|
|
extern JS_PUBLIC_API(bool)
|
2014-01-17 18:08:51 +00:00
|
|
|
JS_GetArrayLength(JSContext *cx, JS::Handle<JSObject*> obj, uint32_t *lengthp);
|
1998-03-28 02:44:41 +00:00
|
|
|
|
2013-08-08 22:53:04 +00:00
|
|
|
extern JS_PUBLIC_API(bool)
|
2014-01-17 18:08:51 +00:00
|
|
|
JS_SetArrayLength(JSContext *cx, JS::Handle<JSObject*> obj, uint32_t length);
|
1998-03-28 02:44:41 +00:00
|
|
|
|
2013-08-08 22:53:04 +00:00
|
|
|
extern JS_PUBLIC_API(bool)
|
2014-04-30 09:10:33 +00:00
|
|
|
JS_DefineElement(JSContext *cx, JS::HandleObject obj, uint32_t index, JS::HandleValue value,
|
|
|
|
unsigned attrs,
|
2014-10-29 19:06:31 +00:00
|
|
|
JSNative getter = nullptr, JSNative setter = nullptr);
|
2014-04-30 09:10:33 +00:00
|
|
|
|
|
|
|
extern JS_PUBLIC_API(bool)
|
|
|
|
JS_DefineElement(JSContext *cx, JS::HandleObject obj, uint32_t index, JS::HandleObject value,
|
|
|
|
unsigned attrs,
|
2014-10-29 19:06:31 +00:00
|
|
|
JSNative getter = nullptr, JSNative setter = nullptr);
|
2014-04-30 09:10:33 +00:00
|
|
|
|
|
|
|
extern JS_PUBLIC_API(bool)
|
|
|
|
JS_DefineElement(JSContext *cx, JS::HandleObject obj, uint32_t index, JS::HandleString value,
|
|
|
|
unsigned attrs,
|
2014-10-29 19:06:31 +00:00
|
|
|
JSNative getter = nullptr, JSNative setter = nullptr);
|
2014-04-30 09:10:33 +00:00
|
|
|
|
|
|
|
extern JS_PUBLIC_API(bool)
|
|
|
|
JS_DefineElement(JSContext *cx, JS::HandleObject obj, uint32_t index, int32_t value,
|
|
|
|
unsigned attrs,
|
2014-10-29 19:06:31 +00:00
|
|
|
JSNative getter = nullptr, JSNative setter = nullptr);
|
2014-04-30 09:10:33 +00:00
|
|
|
|
|
|
|
extern JS_PUBLIC_API(bool)
|
|
|
|
JS_DefineElement(JSContext *cx, JS::HandleObject obj, uint32_t index, uint32_t value,
|
|
|
|
unsigned attrs,
|
2014-10-29 19:06:31 +00:00
|
|
|
JSNative getter = nullptr, JSNative setter = nullptr);
|
2014-04-30 09:10:33 +00:00
|
|
|
|
|
|
|
extern JS_PUBLIC_API(bool)
|
|
|
|
JS_DefineElement(JSContext *cx, JS::HandleObject obj, uint32_t index, double value,
|
|
|
|
unsigned attrs,
|
2014-10-29 19:06:31 +00:00
|
|
|
JSNative getter = nullptr, JSNative setter = nullptr);
|
1998-03-28 02:44:41 +00:00
|
|
|
|
2013-08-08 22:53:04 +00:00
|
|
|
extern JS_PUBLIC_API(bool)
|
2014-01-22 11:28:06 +00:00
|
|
|
JS_AlreadyHasOwnElement(JSContext *cx, JS::HandleObject obj, uint32_t index, bool *foundp);
|
2007-11-13 08:28:47 +00:00
|
|
|
|
2013-08-08 22:53:04 +00:00
|
|
|
extern JS_PUBLIC_API(bool)
|
2014-01-22 11:28:06 +00:00
|
|
|
JS_HasElement(JSContext *cx, JS::HandleObject obj, uint32_t index, bool *foundp);
|
2004-07-17 02:39:55 +00:00
|
|
|
|
2013-08-08 22:53:04 +00:00
|
|
|
extern JS_PUBLIC_API(bool)
|
2014-01-31 09:55:20 +00:00
|
|
|
JS_GetElement(JSContext *cx, JS::HandleObject obj, uint32_t index, JS::MutableHandleValue vp);
|
1998-03-28 02:44:41 +00:00
|
|
|
|
2013-08-08 22:53:04 +00:00
|
|
|
extern JS_PUBLIC_API(bool)
|
2014-04-02 14:28:03 +00:00
|
|
|
JS_ForwardGetElementTo(JSContext *cx, JS::HandleObject obj, uint32_t index,
|
|
|
|
JS::HandleObject onBehalfOf, JS::MutableHandleValue vp);
|
2011-11-04 16:18:38 +00:00
|
|
|
|
2013-08-08 22:53:04 +00:00
|
|
|
extern JS_PUBLIC_API(bool)
|
2014-01-25 09:31:17 +00:00
|
|
|
JS_SetElement(JSContext *cx, JS::HandleObject obj, uint32_t index, JS::HandleValue v);
|
|
|
|
|
|
|
|
extern JS_PUBLIC_API(bool)
|
|
|
|
JS_SetElement(JSContext *cx, JS::HandleObject obj, uint32_t index, JS::HandleObject v);
|
|
|
|
|
|
|
|
extern JS_PUBLIC_API(bool)
|
|
|
|
JS_SetElement(JSContext *cx, JS::HandleObject obj, uint32_t index, JS::HandleString v);
|
|
|
|
|
|
|
|
extern JS_PUBLIC_API(bool)
|
|
|
|
JS_SetElement(JSContext *cx, JS::HandleObject obj, uint32_t index, int32_t v);
|
|
|
|
|
|
|
|
extern JS_PUBLIC_API(bool)
|
|
|
|
JS_SetElement(JSContext *cx, JS::HandleObject obj, uint32_t index, uint32_t v);
|
|
|
|
|
|
|
|
extern JS_PUBLIC_API(bool)
|
|
|
|
JS_SetElement(JSContext *cx, JS::HandleObject obj, uint32_t index, double v);
|
1998-03-28 02:44:41 +00:00
|
|
|
|
2013-08-08 22:53:04 +00:00
|
|
|
extern JS_PUBLIC_API(bool)
|
2014-01-22 11:28:06 +00:00
|
|
|
JS_DeleteElement(JSContext *cx, JS::HandleObject obj, uint32_t index);
|
1998-03-28 02:44:41 +00:00
|
|
|
|
2013-08-08 22:53:04 +00:00
|
|
|
extern JS_PUBLIC_API(bool)
|
2015-02-04 16:20:04 +00:00
|
|
|
JS_DeleteElement(JSContext *cx, JS::HandleObject obj, uint32_t index, JS::ObjectOpResult &result);
|
1998-04-24 00:31:11 +00:00
|
|
|
|
2012-08-23 18:23:28 +00:00
|
|
|
/*
|
|
|
|
* Assign 'undefined' to all of the object's non-reserved slots. Note: this is
|
|
|
|
* done for all slots, regardless of the associated property descriptor.
|
|
|
|
*/
|
|
|
|
JS_PUBLIC_API(void)
|
|
|
|
JS_SetAllNonReservedSlotsToUndefined(JSContext *cx, JSObject *objArg);
|
1998-03-28 02:44:41 +00:00
|
|
|
|
2012-08-24 04:29:42 +00:00
|
|
|
/*
|
2014-08-12 23:59:12 +00:00
|
|
|
* Create a new array buffer with the given contents. It must be legal to pass
|
|
|
|
* these contents to free(). On success, the ownership is transferred to the
|
|
|
|
* new array buffer.
|
2012-08-24 04:29:42 +00:00
|
|
|
*/
|
|
|
|
extern JS_PUBLIC_API(JSObject *)
|
2014-03-17 17:46:04 +00:00
|
|
|
JS_NewArrayBufferWithContents(JSContext *cx, size_t nbytes, void *contents);
|
2012-08-24 04:29:42 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Steal the contents of the given array buffer. The array buffer has its
|
|
|
|
* length set to 0 and its contents array cleared. The caller takes ownership
|
2014-03-17 17:46:04 +00:00
|
|
|
* of the return value and must free it or transfer ownership via
|
2012-08-24 04:29:42 +00:00
|
|
|
* JS_NewArrayBufferWithContents when done using it.
|
|
|
|
*/
|
2014-03-17 17:46:04 +00:00
|
|
|
extern JS_PUBLIC_API(void *)
|
|
|
|
JS_StealArrayBufferContents(JSContext *cx, JS::HandleObject obj);
|
2012-08-24 04:29:42 +00:00
|
|
|
|
|
|
|
/*
|
2014-08-12 23:59:12 +00:00
|
|
|
* Create a new mapped array buffer with the given memory mapped contents. It
|
|
|
|
* must be legal to free the contents pointer by unmapping it. On success,
|
|
|
|
* ownership is transferred to the new mapped array buffer.
|
2014-04-16 11:26:39 +00:00
|
|
|
*/
|
|
|
|
extern JS_PUBLIC_API(JSObject *)
|
|
|
|
JS_NewMappedArrayBufferWithContents(JSContext *cx, size_t nbytes, void *contents);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Create memory mapped array buffer contents.
|
|
|
|
* Caller must take care of closing fd after calling this function.
|
|
|
|
*/
|
|
|
|
extern JS_PUBLIC_API(void *)
|
|
|
|
JS_CreateMappedArrayBufferContents(int fd, size_t offset, size_t length);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Release the allocated resource of mapped array buffer contents before the
|
|
|
|
* object is created.
|
|
|
|
* If a new object has been created by JS_NewMappedArrayBufferWithContents()
|
|
|
|
* with this content, then JS_NeuterArrayBuffer() should be used instead to
|
|
|
|
* release the resource used by the object.
|
|
|
|
*/
|
|
|
|
extern JS_PUBLIC_API(void)
|
|
|
|
JS_ReleaseMappedArrayBufferContents(void *contents, size_t length);
|
|
|
|
|
1998-04-24 00:31:11 +00:00
|
|
|
extern JS_PUBLIC_API(JSIdArray *)
|
2014-04-02 14:28:03 +00:00
|
|
|
JS_Enumerate(JSContext *cx, JS::HandleObject obj);
|
1998-04-24 00:31:11 +00:00
|
|
|
|
2012-02-05 20:07:23 +00:00
|
|
|
extern JS_PUBLIC_API(jsval)
|
2013-04-16 01:16:13 +00:00
|
|
|
JS_GetReservedSlot(JSObject *obj, uint32_t index);
|
- Add JS_GetReservedSlot, JS_SetReservedSlot, and JSCLASS_HAS_RESERVED_SLOTS(n)
to the JS API, for per class extra slots beyond JSSLOT_PRIVATE (or starting
there for a class that lacks JSCLASS_HAS_PRIVATE). To avoid penalizing all
instances, these slots are allocated only upon first property-owned slot
allocation, or upon first JS_SetReservedSlot.
This entailed adding getRequiredSlot and setRequiredSlot hooks to the
JSObjectOps struct, and making obj->slots self-describing, a la BSTR. It
also afforded me a chance to clean up obj->slots locking so that non-native
JSObjectOps didn't risk unlocked accesses! Now there are thread-safe hooks
for all uses of obj.
First consumer is the new, DOM-glue-unifying XPConnect, which needs two
slots per wrapped function. Hence the change to js_FunctionClass.flags'
initializer.
- Commented the heck out of JSClass and JSObjectOps function typedefs in
jspubtd.h. I hope embedders see these comments!
- Fix JS_XDRValue's default case to handle int exclusively, there is no other
possible type (and therefore no JSMSG_BAD_JVAL_TYPE error).
- Clean up tabs in select old, tab-ridden files and sections.
- s/\<fh\>/file/g for stdio FILE * canonical variable names.
2001-04-05 01:53:24 +00:00
|
|
|
|
2012-02-05 20:07:23 +00:00
|
|
|
extern JS_PUBLIC_API(void)
|
2013-04-16 01:16:13 +00:00
|
|
|
JS_SetReservedSlot(JSObject *obj, uint32_t index, jsval v);
|
- Add JS_GetReservedSlot, JS_SetReservedSlot, and JSCLASS_HAS_RESERVED_SLOTS(n)
to the JS API, for per class extra slots beyond JSSLOT_PRIVATE (or starting
there for a class that lacks JSCLASS_HAS_PRIVATE). To avoid penalizing all
instances, these slots are allocated only upon first property-owned slot
allocation, or upon first JS_SetReservedSlot.
This entailed adding getRequiredSlot and setRequiredSlot hooks to the
JSObjectOps struct, and making obj->slots self-describing, a la BSTR. It
also afforded me a chance to clean up obj->slots locking so that non-native
JSObjectOps didn't risk unlocked accesses! Now there are thread-safe hooks
for all uses of obj.
First consumer is the new, DOM-glue-unifying XPConnect, which needs two
slots per wrapped function. Hence the change to js_FunctionClass.flags'
initializer.
- Commented the heck out of JSClass and JSObjectOps function typedefs in
jspubtd.h. I hope embedders see these comments!
- Fix JS_XDRValue's default case to handle int exclusively, there is no other
possible type (and therefore no JSMSG_BAD_JVAL_TYPE error).
- Clean up tabs in select old, tab-ridden files and sections.
- s/\<fh\>/file/g for stdio FILE * canonical variable names.
2001-04-05 01:53:24 +00:00
|
|
|
|
1998-03-28 02:44:41 +00:00
|
|
|
/************************************************************************/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Functions and scripts.
|
|
|
|
*/
|
1998-04-24 00:31:11 +00:00
|
|
|
extern JS_PUBLIC_API(JSFunction *)
|
2012-02-28 23:11:11 +00:00
|
|
|
JS_NewFunction(JSContext *cx, JSNative call, unsigned nargs, unsigned flags,
|
2015-03-09 16:50:03 +00:00
|
|
|
const char *name);
|
1998-03-28 02:44:41 +00:00
|
|
|
|
2010-10-28 15:15:53 +00:00
|
|
|
/*
|
|
|
|
* Create the function with the name given by the id. JSID_IS_STRING(id) must
|
|
|
|
* be true.
|
|
|
|
*/
|
|
|
|
extern JS_PUBLIC_API(JSFunction *)
|
2012-02-28 23:11:11 +00:00
|
|
|
JS_NewFunctionById(JSContext *cx, JSNative call, unsigned nargs, unsigned flags,
|
2015-03-09 16:50:05 +00:00
|
|
|
JS::Handle<jsid> id);
|
2010-10-28 15:15:53 +00:00
|
|
|
|
2013-09-26 14:11:38 +00:00
|
|
|
namespace JS {
|
|
|
|
|
|
|
|
extern JS_PUBLIC_API(JSFunction *)
|
2014-01-17 18:09:38 +00:00
|
|
|
GetSelfHostedFunction(JSContext *cx, const char *selfHostedName, JS::Handle<jsid> id,
|
|
|
|
unsigned nargs);
|
2013-09-26 14:11:38 +00:00
|
|
|
|
|
|
|
} /* namespace JS */
|
|
|
|
|
1998-04-24 00:31:11 +00:00
|
|
|
extern JS_PUBLIC_API(JSObject *)
|
1998-03-28 02:44:41 +00:00
|
|
|
JS_GetFunctionObject(JSFunction *fun);
|
|
|
|
|
2002-03-12 21:58:27 +00:00
|
|
|
/*
|
|
|
|
* Return the function's identifier as a JSString, or null if fun is unnamed.
|
|
|
|
* The returned string lives as long as fun, so you don't need to root a saved
|
|
|
|
* reference to it if fun is well-connected or rooted, and provided you bound
|
|
|
|
* the use of the saved reference by fun's lifetime.
|
|
|
|
*/
|
|
|
|
extern JS_PUBLIC_API(JSString *)
|
|
|
|
JS_GetFunctionId(JSFunction *fun);
|
|
|
|
|
2012-08-19 04:45:54 +00:00
|
|
|
/*
|
|
|
|
* Return a function's display name. This is the defined name if one was given
|
|
|
|
* where the function was defined, or it could be an inferred name by the JS
|
|
|
|
* engine in the case that the function was defined to be anonymous. This can
|
2013-10-07 16:42:55 +00:00
|
|
|
* still return nullptr if a useful display name could not be inferred. The
|
|
|
|
* same restrictions on rooting as those in JS_GetFunctionId apply.
|
2012-08-19 04:45:54 +00:00
|
|
|
*/
|
|
|
|
extern JS_PUBLIC_API(JSString *)
|
|
|
|
JS_GetFunctionDisplayId(JSFunction *fun);
|
|
|
|
|
2006-06-07 20:21:40 +00:00
|
|
|
/*
|
|
|
|
* Return the arity (length) of fun.
|
|
|
|
*/
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-09 03:54:10 +00:00
|
|
|
extern JS_PUBLIC_API(uint16_t)
|
2006-06-07 20:21:40 +00:00
|
|
|
JS_GetFunctionArity(JSFunction *fun);
|
|
|
|
|
2014-09-25 11:13:28 +00:00
|
|
|
/*
|
|
|
|
* API for determining callability and constructability. This does the right
|
|
|
|
* thing for proxies.
|
|
|
|
*/
|
|
|
|
namespace JS {
|
|
|
|
|
|
|
|
extern JS_PUBLIC_API(bool)
|
|
|
|
IsCallable(JSObject *obj);
|
|
|
|
|
|
|
|
extern JS_PUBLIC_API(bool)
|
|
|
|
IsConstructor(JSObject *obj);
|
|
|
|
|
|
|
|
} /* namespace JS */
|
|
|
|
|
2002-03-12 21:58:27 +00:00
|
|
|
/*
|
|
|
|
* Infallible predicate to test whether obj is a function object (faster than
|
|
|
|
* comparing obj's class name to "Function", but equivalent unless someone has
|
|
|
|
* overwritten the "Function" identifier with a different constructor and then
|
|
|
|
* created instances using that constructor that might be passed in as obj).
|
|
|
|
*/
|
2013-08-08 22:53:04 +00:00
|
|
|
extern JS_PUBLIC_API(bool)
|
2013-04-16 01:16:13 +00:00
|
|
|
JS_ObjectIsFunction(JSContext *cx, JSObject *obj);
|
2002-03-12 21:58:27 +00:00
|
|
|
|
2013-08-08 22:53:04 +00:00
|
|
|
extern JS_PUBLIC_API(bool)
|
2013-04-16 01:16:13 +00:00
|
|
|
JS_IsNativeFunction(JSObject *funobj, JSNative call);
|
2011-05-23 15:39:25 +00:00
|
|
|
|
2012-11-02 04:35:09 +00:00
|
|
|
/* Return whether the given function is a valid constructor. */
|
2013-08-08 22:53:04 +00:00
|
|
|
extern JS_PUBLIC_API(bool)
|
2012-11-02 04:35:09 +00:00
|
|
|
JS_IsConstructor(JSFunction *fun);
|
|
|
|
|
2012-04-05 17:14:52 +00:00
|
|
|
/*
|
|
|
|
* Bind the given callable to use the given object as "this".
|
|
|
|
*
|
2013-10-07 16:42:55 +00:00
|
|
|
* If |callable| is not callable, will throw and return nullptr.
|
2012-04-05 17:14:52 +00:00
|
|
|
*/
|
|
|
|
extern JS_PUBLIC_API(JSObject*)
|
2014-01-17 18:09:38 +00:00
|
|
|
JS_BindCallable(JSContext *cx, JS::Handle<JSObject*> callable, JS::Handle<JSObject*> newThis);
|
2012-04-05 17:14:52 +00:00
|
|
|
|
2014-12-11 18:31:10 +00:00
|
|
|
// This enum is used to select if properties with JSPROP_DEFINE_LATE flag
|
|
|
|
// should be defined on the object.
|
|
|
|
// Normal JSAPI consumers probably always want DefineAllProperties here.
|
|
|
|
enum PropertyDefinitionBehavior {
|
|
|
|
DefineAllProperties,
|
|
|
|
OnlyDefineLateProperties,
|
|
|
|
DontDefineLateProperties
|
|
|
|
};
|
|
|
|
|
2013-08-08 22:53:04 +00:00
|
|
|
extern JS_PUBLIC_API(bool)
|
2014-12-11 18:31:10 +00:00
|
|
|
JS_DefineFunctions(JSContext *cx, JS::Handle<JSObject*> obj, const JSFunctionSpec *fs,
|
|
|
|
PropertyDefinitionBehavior behavior = DefineAllProperties);
|
1998-03-28 02:44:41 +00:00
|
|
|
|
1998-04-24 00:31:11 +00:00
|
|
|
extern JS_PUBLIC_API(JSFunction *)
|
2014-01-17 18:10:17 +00:00
|
|
|
JS_DefineFunction(JSContext *cx, JS::Handle<JSObject*> obj, const char *name, JSNative call,
|
2012-02-28 23:11:11 +00:00
|
|
|
unsigned nargs, unsigned attrs);
|
1998-03-28 02:44:41 +00:00
|
|
|
|
2004-05-07 03:21:30 +00:00
|
|
|
extern JS_PUBLIC_API(JSFunction *)
|
2014-01-17 18:10:17 +00:00
|
|
|
JS_DefineUCFunction(JSContext *cx, JS::Handle<JSObject*> obj,
|
2014-07-22 04:43:21 +00:00
|
|
|
const char16_t *name, size_t namelen, JSNative call,
|
2012-02-28 23:11:11 +00:00
|
|
|
unsigned nargs, unsigned attrs);
|
2004-05-07 03:21:30 +00:00
|
|
|
|
2010-10-28 15:15:53 +00:00
|
|
|
extern JS_PUBLIC_API(JSFunction *)
|
2014-01-17 18:10:17 +00:00
|
|
|
JS_DefineFunctionById(JSContext *cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JSNative call,
|
2012-02-28 23:11:11 +00:00
|
|
|
unsigned nargs, unsigned attrs);
|
2010-10-28 15:15:53 +00:00
|
|
|
|
2014-10-30 23:40:28 +00:00
|
|
|
namespace JS {
|
|
|
|
|
2012-07-03 17:24:36 +00:00
|
|
|
/*
|
2014-10-30 23:40:28 +00:00
|
|
|
* Clone a top-level function into cx's global. This function will dynamically
|
2012-07-03 17:24:36 +00:00
|
|
|
* fail if funobj was lexically nested inside some other function.
|
|
|
|
*/
|
1998-04-24 00:31:11 +00:00
|
|
|
extern JS_PUBLIC_API(JSObject *)
|
2014-10-30 23:40:28 +00:00
|
|
|
CloneFunctionObject(JSContext *cx, HandleObject funobj);
|
2014-10-30 21:40:15 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* As above, but providing an explicit scope chain. scopeChain must not include
|
|
|
|
* the global object on it; that's implicit. It needs to contain the other
|
|
|
|
* objects that should end up on the clone's scope chain.
|
|
|
|
*/
|
|
|
|
extern JS_PUBLIC_API(JSObject *)
|
|
|
|
CloneFunctionObject(JSContext *cx, HandleObject funobj, AutoObjectVector &scopeChain);
|
|
|
|
|
|
|
|
} // namespace JS
|
|
|
|
|
2000-02-08 01:38:20 +00:00
|
|
|
/*
|
2013-08-07 06:59:54 +00:00
|
|
|
* Given a buffer, return false if the buffer might become a valid
|
2000-02-08 01:38:20 +00:00
|
|
|
* javascript statement with the addition of more lines. Otherwise return
|
2013-08-07 06:59:54 +00:00
|
|
|
* true. The intent is to support interactive compilation - accumulate
|
2000-02-08 01:38:20 +00:00
|
|
|
* lines in a buffer until JS_BufferIsCompilableUnit is true, then pass it to
|
|
|
|
* the compiler.
|
|
|
|
*/
|
2013-08-08 22:53:04 +00:00
|
|
|
extern JS_PUBLIC_API(bool)
|
2014-01-17 18:09:38 +00:00
|
|
|
JS_BufferIsCompilableUnit(JSContext *cx, JS::Handle<JSObject*> obj, const char *utf8,
|
|
|
|
size_t length);
|
2000-02-08 01:38:20 +00:00
|
|
|
|
2014-06-25 22:35:35 +00:00
|
|
|
/*
|
|
|
|
* |script| will always be set. On failure, it will be set to nullptr.
|
|
|
|
*/
|
|
|
|
extern JS_PUBLIC_API(bool)
|
2015-03-19 14:13:33 +00:00
|
|
|
JS_CompileScript(JSContext *cx, const char *ascii, size_t length,
|
2014-06-25 22:35:35 +00:00
|
|
|
const JS::CompileOptions &options,
|
|
|
|
JS::MutableHandleScript script);
|
1998-03-28 02:44:41 +00:00
|
|
|
|
2014-06-25 22:35:35 +00:00
|
|
|
/*
|
|
|
|
* |script| will always be set. On failure, it will be set to nullptr.
|
|
|
|
*/
|
|
|
|
extern JS_PUBLIC_API(bool)
|
2015-03-19 14:13:34 +00:00
|
|
|
JS_CompileUCScript(JSContext *cx, const char16_t *chars, size_t length,
|
2014-06-25 22:35:35 +00:00
|
|
|
const JS::CompileOptions &options,
|
|
|
|
JS::MutableHandleScript script);
|
1998-03-28 02:44:41 +00:00
|
|
|
|
2011-09-02 06:46:00 +00:00
|
|
|
extern JS_PUBLIC_API(JSObject *)
|
2011-09-22 10:08:55 +00:00
|
|
|
JS_GetGlobalFromScript(JSScript *script);
|
2011-09-02 06:46:00 +00:00
|
|
|
|
2014-10-12 17:37:40 +00:00
|
|
|
extern JS_PUBLIC_API(const char *)
|
|
|
|
JS_GetScriptFilename(JSScript *script);
|
|
|
|
|
|
|
|
extern JS_PUBLIC_API(unsigned)
|
|
|
|
JS_GetScriptBaseLineNumber(JSContext *cx, JSScript *script);
|
|
|
|
|
|
|
|
extern JS_PUBLIC_API(JSScript *)
|
|
|
|
JS_GetFunctionScript(JSContext *cx, JS::HandleFunction fun);
|
|
|
|
|
2012-07-26 00:23:04 +00:00
|
|
|
namespace JS {
|
|
|
|
|
|
|
|
/* Options for JavaScript compilation. */
|
2013-11-08 05:07:18 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* In the most common use case, a CompileOptions instance is allocated on the
|
|
|
|
* stack, and holds non-owning references to non-POD option values: strings;
|
|
|
|
* principals; objects; and so on. The code declaring the instance guarantees
|
|
|
|
* that such option values will outlive the CompileOptions itself: objects are
|
|
|
|
* otherwise rooted; principals have had their reference counts bumped; strings
|
|
|
|
* will not be freed until the CompileOptions goes out of scope. In this
|
|
|
|
* situation, CompileOptions only refers to things others own, so it can be
|
|
|
|
* lightweight.
|
|
|
|
*
|
|
|
|
* In some cases, however, we need to hold compilation options with a
|
|
|
|
* non-stack-like lifetime. For example, JS::CompileOffThread needs to save
|
|
|
|
* compilation options where a worker thread can find them, and then return
|
|
|
|
* immediately. The worker thread will come along at some later point, and use
|
|
|
|
* the options.
|
|
|
|
*
|
|
|
|
* The compiler itself just needs to be able to access a collection of options;
|
|
|
|
* it doesn't care who owns them, or what's keeping them alive. It does its own
|
|
|
|
* addrefs/copies/tracing/etc.
|
|
|
|
*
|
|
|
|
* So, we have a class hierarchy that reflects these three use cases:
|
|
|
|
*
|
|
|
|
* - ReadOnlyCompileOptions is the common base class. It can be used by code
|
|
|
|
* that simply needs to access options set elsewhere, like the compiler.
|
|
|
|
*
|
|
|
|
* - The usual CompileOptions class must be stack-allocated, and holds
|
|
|
|
* non-owning references to the filename, element, and so on. It's derived
|
|
|
|
* from ReadOnlyCompileOptions, so the compiler can use it.
|
|
|
|
*
|
|
|
|
* - OwningCompileOptions roots / copies / reference counts of all its values,
|
|
|
|
* and unroots / frees / releases them when it is destructed. It too is
|
|
|
|
* derived from ReadOnlyCompileOptions, so the compiler accepts it.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The common base class for the CompileOptions hierarchy.
|
|
|
|
*
|
|
|
|
* Use this in code that only needs to access compilation options created
|
|
|
|
* elsewhere, like the compiler. Don't instantiate this class (the constructor
|
|
|
|
* is protected anyway); instead, create instances only of the derived classes:
|
|
|
|
* CompileOptions and OwningCompileOptions.
|
|
|
|
*/
|
2014-01-14 21:20:24 +00:00
|
|
|
class JS_FRIEND_API(ReadOnlyCompileOptions)
|
2013-08-01 18:47:39 +00:00
|
|
|
{
|
2014-03-06 22:28:05 +00:00
|
|
|
friend class CompileOptions;
|
|
|
|
|
2013-11-08 05:07:18 +00:00
|
|
|
protected:
|
2014-09-29 08:44:30 +00:00
|
|
|
// The Web Platform allows scripts to be loaded from arbitrary cross-origin
|
|
|
|
// sources. This allows an attack by which a malicious website loads a
|
|
|
|
// sensitive file (say, a bank statement) cross-origin (using the user's
|
|
|
|
// cookies), and sniffs the generated syntax errors (via a window.onerror
|
|
|
|
// handler) for juicy morsels of its contents.
|
|
|
|
//
|
|
|
|
// To counter this attack, HTML5 specifies that script errors should be
|
|
|
|
// sanitized ("muted") when the script is not same-origin with the global
|
|
|
|
// for which it is loaded. Callers should set this flag for cross-origin
|
|
|
|
// scripts, and it will be propagated appropriately to child scripts and
|
|
|
|
// passed back in JSErrorReports.
|
|
|
|
bool mutedErrors_;
|
2013-11-08 05:07:18 +00:00
|
|
|
const char *filename_;
|
2014-02-04 21:23:20 +00:00
|
|
|
const char *introducerFilename_;
|
2014-07-22 04:43:21 +00:00
|
|
|
const char16_t *sourceMapURL_;
|
2013-11-08 05:07:18 +00:00
|
|
|
|
|
|
|
// This constructor leaves 'version' set to JSVERSION_UNKNOWN. The structure
|
|
|
|
// is unusable until that's set to something more specific; the derived
|
|
|
|
// classes' constructors take care of that, in ways appropriate to their
|
|
|
|
// purpose.
|
|
|
|
ReadOnlyCompileOptions()
|
2014-09-29 08:44:30 +00:00
|
|
|
: mutedErrors_(false),
|
2013-11-08 05:07:18 +00:00
|
|
|
filename_(nullptr),
|
2014-02-04 21:23:20 +00:00
|
|
|
introducerFilename_(nullptr),
|
2013-11-08 05:07:18 +00:00
|
|
|
sourceMapURL_(nullptr),
|
|
|
|
version(JSVERSION_UNKNOWN),
|
|
|
|
versionSet(false),
|
|
|
|
utf8(false),
|
|
|
|
lineno(1),
|
|
|
|
column(0),
|
|
|
|
compileAndGo(false),
|
|
|
|
forEval(false),
|
|
|
|
noScriptRval(false),
|
|
|
|
selfHostingMode(false),
|
|
|
|
canLazilyParse(true),
|
|
|
|
strictOption(false),
|
|
|
|
extraWarningsOption(false),
|
|
|
|
werrorOption(false),
|
|
|
|
asmJSOption(false),
|
2014-01-21 00:00:18 +00:00
|
|
|
forceAsync(false),
|
2014-03-05 20:47:10 +00:00
|
|
|
installedFile(false),
|
2014-04-22 21:08:27 +00:00
|
|
|
sourceIsLazy(false),
|
2014-02-07 20:36:03 +00:00
|
|
|
introductionType(nullptr),
|
2014-02-04 21:23:20 +00:00
|
|
|
introductionLineno(0),
|
|
|
|
introductionOffset(0),
|
|
|
|
hasIntroductionInfo(false)
|
2013-11-08 05:07:18 +00:00
|
|
|
{ }
|
|
|
|
|
|
|
|
// Set all POD options (those not requiring reference counts, copies,
|
|
|
|
// rooting, or other hand-holding) to their values in |rhs|.
|
|
|
|
void copyPODOptions(const ReadOnlyCompileOptions &rhs);
|
2013-08-01 18:47:39 +00:00
|
|
|
|
|
|
|
public:
|
2013-11-08 05:07:18 +00:00
|
|
|
// Read-only accessors for non-POD options. The proper way to set these
|
|
|
|
// depends on the derived type.
|
2014-09-29 08:44:30 +00:00
|
|
|
bool mutedErrors() const { return mutedErrors_; }
|
2013-11-08 05:07:18 +00:00
|
|
|
const char *filename() const { return filename_; }
|
2014-02-04 21:23:20 +00:00
|
|
|
const char *introducerFilename() const { return introducerFilename_; }
|
2014-07-22 04:43:21 +00:00
|
|
|
const char16_t *sourceMapURL() const { return sourceMapURL_; }
|
2013-11-08 05:07:18 +00:00
|
|
|
virtual JSObject *element() const = 0;
|
2014-01-23 00:41:16 +00:00
|
|
|
virtual JSString *elementAttributeName() const = 0;
|
2014-02-26 23:20:00 +00:00
|
|
|
virtual JSScript *introductionScript() const = 0;
|
2013-08-01 18:47:39 +00:00
|
|
|
|
2013-11-08 05:07:18 +00:00
|
|
|
// POD options.
|
2012-07-26 00:23:04 +00:00
|
|
|
JSVersion version;
|
|
|
|
bool versionSet;
|
|
|
|
bool utf8;
|
|
|
|
unsigned lineno;
|
2013-05-30 12:29:56 +00:00
|
|
|
unsigned column;
|
2012-07-26 00:23:04 +00:00
|
|
|
bool compileAndGo;
|
2013-05-07 14:27:14 +00:00
|
|
|
bool forEval;
|
2012-07-26 00:23:04 +00:00
|
|
|
bool noScriptRval;
|
2012-07-23 21:01:54 +00:00
|
|
|
bool selfHostingMode;
|
2013-05-30 12:29:56 +00:00
|
|
|
bool canLazilyParse;
|
2013-07-10 15:29:52 +00:00
|
|
|
bool strictOption;
|
|
|
|
bool extraWarningsOption;
|
|
|
|
bool werrorOption;
|
|
|
|
bool asmJSOption;
|
2014-01-21 00:00:18 +00:00
|
|
|
bool forceAsync;
|
2014-03-05 20:47:10 +00:00
|
|
|
bool installedFile; // 'true' iff pre-compiling js file in packaged app
|
2014-04-22 21:08:27 +00:00
|
|
|
bool sourceIsLazy;
|
2012-07-26 00:23:04 +00:00
|
|
|
|
2014-02-07 20:36:03 +00:00
|
|
|
// |introductionType| is a statically allocated C string:
|
2014-02-04 21:23:20 +00:00
|
|
|
// one of "eval", "Function", or "GeneratorFunction".
|
2014-02-07 20:36:03 +00:00
|
|
|
const char *introductionType;
|
2014-02-04 21:23:20 +00:00
|
|
|
unsigned introductionLineno;
|
|
|
|
uint32_t introductionOffset;
|
|
|
|
bool hasIntroductionInfo;
|
|
|
|
|
2013-11-08 05:07:18 +00:00
|
|
|
private:
|
|
|
|
static JSObject * const nullObjectPtr;
|
2015-01-06 23:35:02 +00:00
|
|
|
void operator=(const ReadOnlyCompileOptions &) = delete;
|
2013-11-08 05:07:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Compilation options, with dynamic lifetime. An instance of this type
|
|
|
|
* makes a copy of / holds / roots all dynamically allocated resources
|
|
|
|
* (principals; elements; strings) that it refers to. Its destructor frees
|
|
|
|
* / drops / unroots them. This is heavier than CompileOptions, below, but
|
|
|
|
* unlike CompileOptions, it can outlive any given stack frame.
|
|
|
|
*
|
|
|
|
* Note that this *roots* any JS values it refers to - they're live
|
|
|
|
* unconditionally. Thus, instances of this type can't be owned, directly
|
|
|
|
* or indirectly, by a JavaScript object: if any value that this roots ever
|
|
|
|
* comes to refer to the object that owns this, then the whole cycle, and
|
|
|
|
* anything else it entrains, will never be freed.
|
|
|
|
*/
|
2014-01-14 21:20:24 +00:00
|
|
|
class JS_FRIEND_API(OwningCompileOptions) : public ReadOnlyCompileOptions
|
2013-11-08 05:07:18 +00:00
|
|
|
{
|
|
|
|
JSRuntime *runtime;
|
|
|
|
PersistentRootedObject elementRoot;
|
2014-01-23 00:41:16 +00:00
|
|
|
PersistentRootedString elementAttributeNameRoot;
|
2014-02-26 23:20:00 +00:00
|
|
|
PersistentRootedScript introductionScriptRoot;
|
2013-11-08 05:07:18 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
// A minimal constructor, for use with OwningCompileOptions::copy. This
|
|
|
|
// leaves |this.version| set to JSVERSION_UNKNOWN; the instance
|
|
|
|
// shouldn't be used until we've set that to something real (as |copy|
|
|
|
|
// will).
|
|
|
|
explicit OwningCompileOptions(JSContext *cx);
|
|
|
|
~OwningCompileOptions();
|
|
|
|
|
|
|
|
JSObject *element() const MOZ_OVERRIDE { return elementRoot; }
|
2014-01-23 00:41:16 +00:00
|
|
|
JSString *elementAttributeName() const MOZ_OVERRIDE { return elementAttributeNameRoot; }
|
2014-02-26 23:20:00 +00:00
|
|
|
JSScript *introductionScript() const MOZ_OVERRIDE { return introductionScriptRoot; }
|
2013-11-08 05:07:18 +00:00
|
|
|
|
|
|
|
// Set this to a copy of |rhs|. Return false on OOM.
|
|
|
|
bool copy(JSContext *cx, const ReadOnlyCompileOptions &rhs);
|
|
|
|
|
|
|
|
/* These setters make copies of their string arguments, and are fallible. */
|
2014-01-23 00:41:16 +00:00
|
|
|
bool setFile(JSContext *cx, const char *f);
|
2013-11-08 05:07:18 +00:00
|
|
|
bool setFileAndLine(JSContext *cx, const char *f, unsigned l);
|
2014-07-22 04:43:21 +00:00
|
|
|
bool setSourceMapURL(JSContext *cx, const char16_t *s);
|
2014-02-04 21:23:20 +00:00
|
|
|
bool setIntroducerFilename(JSContext *cx, const char *s);
|
2013-11-08 05:07:18 +00:00
|
|
|
|
|
|
|
/* These setters are infallible, and can be chained. */
|
2014-07-22 04:43:21 +00:00
|
|
|
OwningCompileOptions &setLine(unsigned l) { lineno = l; return *this; }
|
2014-01-23 00:41:16 +00:00
|
|
|
OwningCompileOptions &setElement(JSObject *e) {
|
|
|
|
elementRoot = e;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
OwningCompileOptions &setElementAttributeName(JSString *p) {
|
|
|
|
elementAttributeNameRoot = p;
|
|
|
|
return *this;
|
|
|
|
}
|
2014-02-26 23:20:00 +00:00
|
|
|
OwningCompileOptions &setIntroductionScript(JSScript *s) {
|
|
|
|
introductionScriptRoot = s;
|
|
|
|
return *this;
|
|
|
|
}
|
2014-09-29 08:44:30 +00:00
|
|
|
OwningCompileOptions &setMutedErrors(bool mute) {
|
|
|
|
mutedErrors_ = mute;
|
2013-11-08 05:07:18 +00:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
OwningCompileOptions &setVersion(JSVersion v) {
|
|
|
|
version = v;
|
|
|
|
versionSet = true;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
OwningCompileOptions &setUTF8(bool u) { utf8 = u; return *this; }
|
|
|
|
OwningCompileOptions &setColumn(unsigned c) { column = c; return *this; }
|
|
|
|
OwningCompileOptions &setCompileAndGo(bool cng) { compileAndGo = cng; return *this; }
|
|
|
|
OwningCompileOptions &setForEval(bool eval) { forEval = eval; return *this; }
|
|
|
|
OwningCompileOptions &setNoScriptRval(bool nsr) { noScriptRval = nsr; return *this; }
|
|
|
|
OwningCompileOptions &setSelfHostingMode(bool shm) { selfHostingMode = shm; return *this; }
|
|
|
|
OwningCompileOptions &setCanLazilyParse(bool clp) { canLazilyParse = clp; return *this; }
|
2014-04-22 21:08:27 +00:00
|
|
|
OwningCompileOptions &setSourceIsLazy(bool l) { sourceIsLazy = l; return *this; }
|
2014-02-24 23:31:47 +00:00
|
|
|
OwningCompileOptions &setIntroductionType(const char *t) { introductionType = t; return *this; }
|
2014-02-04 21:23:20 +00:00
|
|
|
bool setIntroductionInfo(JSContext *cx, const char *introducerFn, const char *intro,
|
2014-02-26 23:20:00 +00:00
|
|
|
unsigned line, JSScript *script, uint32_t offset)
|
2014-02-04 21:23:20 +00:00
|
|
|
{
|
|
|
|
if (!setIntroducerFilename(cx, introducerFn))
|
|
|
|
return false;
|
2014-02-07 20:36:03 +00:00
|
|
|
introductionType = intro;
|
2014-02-04 21:23:20 +00:00
|
|
|
introductionLineno = line;
|
2014-02-26 23:20:00 +00:00
|
|
|
introductionScriptRoot = script;
|
2014-02-04 21:23:20 +00:00
|
|
|
introductionOffset = offset;
|
|
|
|
hasIntroductionInfo = true;
|
|
|
|
return true;
|
|
|
|
}
|
2014-01-23 00:41:15 +00:00
|
|
|
|
2014-03-06 22:28:05 +00:00
|
|
|
private:
|
2015-01-06 23:35:02 +00:00
|
|
|
void operator=(const CompileOptions &rhs) = delete;
|
2013-11-08 05:07:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Compilation options stored on the stack. An instance of this type
|
|
|
|
* simply holds references to dynamically allocated resources (element;
|
|
|
|
* filename; source map URL) that are owned by something else. If you
|
|
|
|
* create an instance of this type, it's up to you to guarantee that
|
|
|
|
* everything you store in it will outlive it.
|
|
|
|
*/
|
2014-01-14 21:20:24 +00:00
|
|
|
class MOZ_STACK_CLASS JS_FRIEND_API(CompileOptions) : public ReadOnlyCompileOptions
|
2013-11-08 05:07:18 +00:00
|
|
|
{
|
|
|
|
RootedObject elementRoot;
|
2014-01-23 00:41:16 +00:00
|
|
|
RootedString elementAttributeNameRoot;
|
2014-02-26 23:20:00 +00:00
|
|
|
RootedScript introductionScriptRoot;
|
2013-11-08 05:07:18 +00:00
|
|
|
|
|
|
|
public:
|
2013-06-14 11:58:28 +00:00
|
|
|
explicit CompileOptions(JSContext *cx, JSVersion version = JSVERSION_UNKNOWN);
|
2013-11-08 05:07:18 +00:00
|
|
|
CompileOptions(js::ContextFriendFields *cx, const ReadOnlyCompileOptions &rhs)
|
2014-02-26 23:20:00 +00:00
|
|
|
: ReadOnlyCompileOptions(), elementRoot(cx), elementAttributeNameRoot(cx),
|
|
|
|
introductionScriptRoot(cx)
|
2013-11-08 05:07:18 +00:00
|
|
|
{
|
|
|
|
copyPODOptions(rhs);
|
|
|
|
|
2014-09-29 08:44:30 +00:00
|
|
|
mutedErrors_ = rhs.mutedErrors_;
|
2013-11-08 05:07:18 +00:00
|
|
|
filename_ = rhs.filename();
|
|
|
|
sourceMapURL_ = rhs.sourceMapURL();
|
|
|
|
elementRoot = rhs.element();
|
2014-01-23 00:41:16 +00:00
|
|
|
elementAttributeNameRoot = rhs.elementAttributeName();
|
2014-02-26 23:20:00 +00:00
|
|
|
introductionScriptRoot = rhs.introductionScript();
|
2013-11-08 05:07:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
JSObject *element() const MOZ_OVERRIDE { return elementRoot; }
|
2014-01-23 00:41:16 +00:00
|
|
|
JSString *elementAttributeName() const MOZ_OVERRIDE { return elementAttributeNameRoot; }
|
2014-02-26 23:20:00 +00:00
|
|
|
JSScript *introductionScript() const MOZ_OVERRIDE { return introductionScriptRoot; }
|
2013-11-08 05:07:18 +00:00
|
|
|
|
2014-01-23 00:41:16 +00:00
|
|
|
CompileOptions &setFile(const char *f) { filename_ = f; return *this; }
|
|
|
|
CompileOptions &setLine(unsigned l) { lineno = l; return *this; }
|
2012-07-26 00:23:04 +00:00
|
|
|
CompileOptions &setFileAndLine(const char *f, unsigned l) {
|
2013-11-08 05:07:18 +00:00
|
|
|
filename_ = f; lineno = l; return *this;
|
2012-07-26 00:23:04 +00:00
|
|
|
}
|
2014-07-22 04:43:21 +00:00
|
|
|
CompileOptions &setSourceMapURL(const char16_t *s) { sourceMapURL_ = s; return *this; }
|
|
|
|
CompileOptions &setElement(JSObject *e) { elementRoot = e; return *this; }
|
2014-01-23 00:41:16 +00:00
|
|
|
CompileOptions &setElementAttributeName(JSString *p) {
|
|
|
|
elementAttributeNameRoot = p;
|
|
|
|
return *this;
|
|
|
|
}
|
2014-02-26 23:20:00 +00:00
|
|
|
CompileOptions &setIntroductionScript(JSScript *s) {
|
|
|
|
introductionScriptRoot = s;
|
|
|
|
return *this;
|
|
|
|
}
|
2014-09-29 08:44:30 +00:00
|
|
|
CompileOptions &setMutedErrors(bool mute) {
|
|
|
|
mutedErrors_ = mute;
|
2013-11-08 05:07:18 +00:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
CompileOptions &setVersion(JSVersion v) {
|
|
|
|
version = v;
|
|
|
|
versionSet = true;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
CompileOptions &setUTF8(bool u) { utf8 = u; return *this; }
|
2013-05-30 12:29:56 +00:00
|
|
|
CompileOptions &setColumn(unsigned c) { column = c; return *this; }
|
2012-07-26 00:23:04 +00:00
|
|
|
CompileOptions &setCompileAndGo(bool cng) { compileAndGo = cng; return *this; }
|
2013-05-07 14:27:14 +00:00
|
|
|
CompileOptions &setForEval(bool eval) { forEval = eval; return *this; }
|
2012-07-26 00:23:04 +00:00
|
|
|
CompileOptions &setNoScriptRval(bool nsr) { noScriptRval = nsr; return *this; }
|
2012-07-23 21:01:54 +00:00
|
|
|
CompileOptions &setSelfHostingMode(bool shm) { selfHostingMode = shm; return *this; }
|
2013-05-30 12:29:56 +00:00
|
|
|
CompileOptions &setCanLazilyParse(bool clp) { canLazilyParse = clp; return *this; }
|
2014-04-22 21:08:27 +00:00
|
|
|
CompileOptions &setSourceIsLazy(bool l) { sourceIsLazy = l; return *this; }
|
2014-02-24 23:31:47 +00:00
|
|
|
CompileOptions &setIntroductionType(const char *t) { introductionType = t; return *this; }
|
2014-02-04 21:23:20 +00:00
|
|
|
CompileOptions &setIntroductionInfo(const char *introducerFn, const char *intro,
|
2014-02-26 23:20:00 +00:00
|
|
|
unsigned line, JSScript *script, uint32_t offset)
|
2014-02-04 21:23:20 +00:00
|
|
|
{
|
|
|
|
introducerFilename_ = introducerFn;
|
2014-02-07 20:36:03 +00:00
|
|
|
introductionType = intro;
|
2014-02-04 21:23:20 +00:00
|
|
|
introductionLineno = line;
|
2014-02-26 23:20:00 +00:00
|
|
|
introductionScriptRoot = script;
|
2014-02-04 21:23:20 +00:00
|
|
|
introductionOffset = offset;
|
|
|
|
hasIntroductionInfo = true;
|
|
|
|
return *this;
|
|
|
|
}
|
2014-11-26 22:42:53 +00:00
|
|
|
CompileOptions &maybeMakeStrictMode(bool strict) {
|
|
|
|
strictOption = strictOption || strict;
|
|
|
|
return *this;
|
|
|
|
}
|
2014-01-23 00:41:15 +00:00
|
|
|
|
2014-03-06 22:28:05 +00:00
|
|
|
private:
|
2015-01-06 23:35:02 +00:00
|
|
|
void operator=(const CompileOptions &rhs) = delete;
|
2012-07-26 00:23:04 +00:00
|
|
|
};
|
|
|
|
|
2014-06-12 00:38:22 +00:00
|
|
|
/*
|
|
|
|
* |script| will always be set. On failure, it will be set to nullptr.
|
|
|
|
*/
|
|
|
|
extern JS_PUBLIC_API(bool)
|
2015-03-19 14:13:34 +00:00
|
|
|
Compile(JSContext *cx, const ReadOnlyCompileOptions &options,
|
2014-06-12 00:38:22 +00:00
|
|
|
SourceBufferHolder &srcBuf, JS::MutableHandleScript script);
|
2012-07-26 00:23:04 +00:00
|
|
|
|
2014-06-25 22:35:35 +00:00
|
|
|
extern JS_PUBLIC_API(bool)
|
2015-03-19 14:13:34 +00:00
|
|
|
Compile(JSContext *cx, const ReadOnlyCompileOptions &options,
|
2014-06-25 22:35:35 +00:00
|
|
|
const char *bytes, size_t length, JS::MutableHandleScript script);
|
2012-07-26 00:23:04 +00:00
|
|
|
|
2014-06-25 22:35:35 +00:00
|
|
|
extern JS_PUBLIC_API(bool)
|
2015-03-19 14:13:34 +00:00
|
|
|
Compile(JSContext *cx, const ReadOnlyCompileOptions &options,
|
2014-07-22 04:43:21 +00:00
|
|
|
const char16_t *chars, size_t length, JS::MutableHandleScript script);
|
2014-04-25 14:11:56 +00:00
|
|
|
|
2014-06-25 22:35:35 +00:00
|
|
|
extern JS_PUBLIC_API(bool)
|
2015-03-19 14:13:34 +00:00
|
|
|
Compile(JSContext *cx, const ReadOnlyCompileOptions &options, FILE *file,
|
2014-06-25 22:35:35 +00:00
|
|
|
JS::MutableHandleScript script);
|
2012-07-26 00:23:04 +00:00
|
|
|
|
2014-06-25 22:35:35 +00:00
|
|
|
extern JS_PUBLIC_API(bool)
|
2015-03-19 14:13:34 +00:00
|
|
|
Compile(JSContext *cx, const ReadOnlyCompileOptions &options, const char *filename,
|
2014-06-25 22:35:35 +00:00
|
|
|
JS::MutableHandleScript script);
|
2012-07-26 00:23:04 +00:00
|
|
|
|
2013-08-15 21:14:43 +00:00
|
|
|
extern JS_PUBLIC_API(bool)
|
2014-01-21 00:00:18 +00:00
|
|
|
CanCompileOffThread(JSContext *cx, const ReadOnlyCompileOptions &options, size_t length);
|
2013-08-15 21:14:43 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Off thread compilation control flow.
|
|
|
|
*
|
|
|
|
* After successfully triggering an off thread compile of a script, the
|
2013-08-29 15:56:05 +00:00
|
|
|
* callback will eventually be invoked with the specified data and a token
|
|
|
|
* for the compilation. The callback will be invoked while off the main thread,
|
|
|
|
* so must ensure that its operations are thread safe. Afterwards,
|
|
|
|
* FinishOffThreadScript must be invoked on the main thread to get the result
|
2014-04-11 15:47:43 +00:00
|
|
|
* script or nullptr. If maybecx is not specified, the resources will be freed,
|
|
|
|
* but no script will be returned.
|
2013-08-15 21:14:43 +00:00
|
|
|
*
|
|
|
|
* The characters passed in to CompileOffThread must remain live until the
|
|
|
|
* callback is invoked, and the resulting script will be rooted until the call
|
|
|
|
* to FinishOffThreadScript.
|
|
|
|
*/
|
|
|
|
|
|
|
|
extern JS_PUBLIC_API(bool)
|
2014-04-11 15:47:43 +00:00
|
|
|
CompileOffThread(JSContext *cx, const ReadOnlyCompileOptions &options,
|
2014-07-22 04:43:21 +00:00
|
|
|
const char16_t *chars, size_t length,
|
2013-08-15 21:14:43 +00:00
|
|
|
OffThreadCompileCallback callback, void *callbackData);
|
|
|
|
|
2013-08-29 15:56:05 +00:00
|
|
|
extern JS_PUBLIC_API(JSScript *)
|
|
|
|
FinishOffThreadScript(JSContext *maybecx, JSRuntime *rt, void *token);
|
2013-08-15 21:14:43 +00:00
|
|
|
|
2014-10-25 04:50:28 +00:00
|
|
|
/**
|
|
|
|
* Compile a function with scopeChain plus the global as its scope chain.
|
|
|
|
* scopeChain must contain objects in the current compartment of cx. The actual
|
|
|
|
* scope chain used for the function will consist of With wrappers for those
|
|
|
|
* objects, followed by the current global of the compartment cx is in. This
|
|
|
|
* global must not be explicitly included in the scope chain.
|
|
|
|
*/
|
|
|
|
extern JS_PUBLIC_API(bool)
|
|
|
|
CompileFunction(JSContext *cx, AutoObjectVector &scopeChain,
|
|
|
|
const ReadOnlyCompileOptions &options,
|
|
|
|
const char *name, unsigned nargs, const char *const *argnames,
|
|
|
|
const char16_t *chars, size_t length, JS::MutableHandleFunction fun);
|
|
|
|
|
2014-10-30 23:40:28 +00:00
|
|
|
/**
|
|
|
|
* Same as above, but taking a SourceBufferHolder for the function body.
|
|
|
|
*/
|
|
|
|
extern JS_PUBLIC_API(bool)
|
|
|
|
CompileFunction(JSContext *cx, AutoObjectVector &scopeChain,
|
|
|
|
const ReadOnlyCompileOptions &options,
|
|
|
|
const char *name, unsigned nargs, const char *const *argnames,
|
|
|
|
SourceBufferHolder &srcBuf, JS::MutableHandleFunction fun);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Same as above, but taking a const char * for the function body.
|
|
|
|
*/
|
|
|
|
extern JS_PUBLIC_API(bool)
|
|
|
|
CompileFunction(JSContext *cx, AutoObjectVector &scopeChain,
|
|
|
|
const ReadOnlyCompileOptions &options,
|
|
|
|
const char *name, unsigned nargs, const char *const *argnames,
|
|
|
|
const char *bytes, size_t length, JS::MutableHandleFunction fun);
|
|
|
|
|
2012-07-26 00:23:04 +00:00
|
|
|
} /* namespace JS */
|
|
|
|
|
1998-04-24 00:31:11 +00:00
|
|
|
extern JS_PUBLIC_API(JSString *)
|
2014-01-17 18:09:38 +00:00
|
|
|
JS_DecompileScript(JSContext *cx, JS::Handle<JSScript*> script, const char *name, unsigned indent);
|
1998-03-28 02:44:41 +00:00
|
|
|
|
1999-09-21 00:13:48 +00:00
|
|
|
/*
|
|
|
|
* API extension: OR this into indent to avoid pretty-printing the decompiled
|
|
|
|
* source resulting from JS_DecompileFunction{,Body}.
|
|
|
|
*/
|
2012-02-28 23:11:11 +00:00
|
|
|
#define JS_DONT_PRETTY_PRINT ((unsigned)0x8000)
|
1999-09-21 00:13:48 +00:00
|
|
|
|
1998-04-24 00:31:11 +00:00
|
|
|
extern JS_PUBLIC_API(JSString *)
|
2014-01-17 18:09:38 +00:00
|
|
|
JS_DecompileFunction(JSContext *cx, JS::Handle<JSFunction*> fun, unsigned indent);
|
1998-03-28 02:44:41 +00:00
|
|
|
|
1998-04-24 00:31:11 +00:00
|
|
|
extern JS_PUBLIC_API(JSString *)
|
2014-01-17 18:09:38 +00:00
|
|
|
JS_DecompileFunctionBody(JSContext *cx, JS::Handle<JSFunction*> fun, unsigned indent);
|
1998-03-28 02:44:41 +00:00
|
|
|
|
2001-01-20 01:41:55 +00:00
|
|
|
/*
|
2015-03-14 05:36:16 +00:00
|
|
|
* NB: JS_ExecuteScript and the JS::Evaluate APIs come in two flavors: either
|
|
|
|
* they use the global as the scope, or they take an AutoObjectVector of objects
|
|
|
|
* to use as the scope chain. In the former case, the global is also used as
|
|
|
|
* the "this" keyword value and the variables object (ECMA parlance for where
|
|
|
|
* 'var' and 'function' bind names) of the execution context for script. In the
|
|
|
|
* latter case, the first object in the provided list is used, unless the list
|
|
|
|
* is empty, in which case the global is used.
|
2001-01-20 01:41:55 +00:00
|
|
|
*
|
2015-03-14 05:36:16 +00:00
|
|
|
* Using a non-global object as the variables object is problematic: in this
|
|
|
|
* case, variables created by 'var x = 0', e.g., go in that object, but
|
|
|
|
* variables created by assignment to an unbound id, 'x = 0', go in the global.
|
2001-01-20 01:41:55 +00:00
|
|
|
*
|
2015-03-14 05:36:16 +00:00
|
|
|
* ECMA requires that "global code" be executed with the variables object equal
|
|
|
|
* to the global object. But these JS API entry points provide freedom to
|
|
|
|
* execute code against a "sub-global", i.e., a parented or scoped object, in
|
|
|
|
* which case the variables object will differ from the global, resulting in
|
|
|
|
* confusing and non-ECMA explicit vs. implicit variable creation.
|
2001-01-20 01:41:55 +00:00
|
|
|
*
|
|
|
|
* Caveat embedders: unless you already depend on this buggy variables object
|
2014-11-19 04:27:16 +00:00
|
|
|
* binding behavior, you should call RuntimeOptionsRef(rt).setVarObjFix(true)
|
2015-03-14 05:36:16 +00:00
|
|
|
* for each context in the application, if you use the versions of
|
|
|
|
* JS_ExecuteScript and JS::Evaluate that take a scope chain argument, or may
|
|
|
|
* ever use them in the future.
|
2001-01-20 01:41:55 +00:00
|
|
|
*
|
2014-11-19 04:27:16 +00:00
|
|
|
* Why a runtime option? The alternative is to add APIs duplicating those below
|
|
|
|
* for the other value of varobjfix, and that doesn't seem worth the code bloat
|
|
|
|
* cost. Such new entry points would probably have less obvious names, too, so
|
|
|
|
* would not tend to be used. The RuntimeOptionsRef adjustment, OTOH, can be
|
|
|
|
* more easily hacked into existing code that does not depend on the bug; such
|
|
|
|
* code can continue to use the familiar JS::Evaluate, etc., entry points.
|
2001-01-20 01:41:55 +00:00
|
|
|
*/
|
2015-03-14 05:36:16 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Evaluate a script in the scope of the current global of cx.
|
|
|
|
*/
|
2013-08-08 22:53:04 +00:00
|
|
|
extern JS_PUBLIC_API(bool)
|
2015-03-14 05:36:16 +00:00
|
|
|
JS_ExecuteScript(JSContext *cx, JS::HandleScript script, JS::MutableHandleValue rval);
|
1998-03-28 02:44:41 +00:00
|
|
|
|
2013-08-08 22:53:04 +00:00
|
|
|
extern JS_PUBLIC_API(bool)
|
2015-03-14 05:36:16 +00:00
|
|
|
JS_ExecuteScript(JSContext *cx, JS::HandleScript script);
|
2014-04-01 10:34:39 +00:00
|
|
|
|
2014-11-12 22:04:29 +00:00
|
|
|
/*
|
|
|
|
* As above, but providing an explicit scope chain. scopeChain must not include
|
|
|
|
* the global object on it; that's implicit. It needs to contain the other
|
2015-03-14 05:36:16 +00:00
|
|
|
* objects that should end up on the script's scope chain.
|
2014-11-12 22:04:29 +00:00
|
|
|
*/
|
|
|
|
extern JS_PUBLIC_API(bool)
|
|
|
|
JS_ExecuteScript(JSContext *cx, JS::AutoObjectVector &scopeChain,
|
|
|
|
JS::HandleScript script, JS::MutableHandleValue rval);
|
|
|
|
|
|
|
|
extern JS_PUBLIC_API(bool)
|
|
|
|
JS_ExecuteScript(JSContext *cx, JS::AutoObjectVector &scopeChain, JS::HandleScript script);
|
|
|
|
|
2014-04-11 15:47:42 +00:00
|
|
|
namespace JS {
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Like the above, but handles a cross-compartment script. If the script is
|
|
|
|
* cross-compartment, it is cloned into the current compartment before executing.
|
|
|
|
*/
|
|
|
|
extern JS_PUBLIC_API(bool)
|
|
|
|
CloneAndExecuteScript(JSContext *cx, JS::Handle<JSObject*> obj, JS::Handle<JSScript*> script);
|
|
|
|
|
|
|
|
} /* namespace JS */
|
|
|
|
|
2012-07-26 00:23:04 +00:00
|
|
|
namespace JS {
|
|
|
|
|
2015-03-14 05:36:16 +00:00
|
|
|
/*
|
|
|
|
* Evaluate the given source buffer in the scope of the current global of cx.
|
|
|
|
*/
|
2014-04-25 14:11:56 +00:00
|
|
|
extern JS_PUBLIC_API(bool)
|
2015-03-14 05:36:16 +00:00
|
|
|
Evaluate(JSContext *cx, const ReadOnlyCompileOptions &options,
|
2014-04-25 14:11:56 +00:00
|
|
|
SourceBufferHolder &srcBuf, JS::MutableHandleValue rval);
|
|
|
|
|
2015-03-14 05:36:16 +00:00
|
|
|
/*
|
|
|
|
* As above, but providing an explicit scope chain. scopeChain must not include
|
|
|
|
* the global object on it; that's implicit. It needs to contain the other
|
|
|
|
* objects that should end up on the script's scope chain.
|
|
|
|
*/
|
2014-11-12 22:04:29 +00:00
|
|
|
extern JS_PUBLIC_API(bool)
|
|
|
|
Evaluate(JSContext *cx, AutoObjectVector &scopeChain, const ReadOnlyCompileOptions &options,
|
|
|
|
SourceBufferHolder &srcBuf, JS::MutableHandleValue rval);
|
|
|
|
|
2015-03-14 05:36:16 +00:00
|
|
|
/*
|
|
|
|
* Evaluate the given character buffer in the scope of the current global of cx.
|
|
|
|
*/
|
|
|
|
extern JS_PUBLIC_API(bool)
|
|
|
|
Evaluate(JSContext *cx, const ReadOnlyCompileOptions &options,
|
|
|
|
const char16_t *chars, size_t length, JS::MutableHandleValue rval);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* As above, but providing an explicit scope chain. scopeChain must not include
|
|
|
|
* the global object on it; that's implicit. It needs to contain the other
|
|
|
|
* objects that should end up on the script's scope chain.
|
|
|
|
*/
|
2012-07-26 00:23:04 +00:00
|
|
|
extern JS_PUBLIC_API(bool)
|
2015-03-14 05:36:16 +00:00
|
|
|
Evaluate(JSContext *cx, AutoObjectVector &scopeChain, const ReadOnlyCompileOptions &options,
|
2014-07-22 04:43:21 +00:00
|
|
|
const char16_t *chars, size_t length, JS::MutableHandleValue rval);
|
2014-04-01 10:34:39 +00:00
|
|
|
|
2015-03-14 05:36:16 +00:00
|
|
|
/*
|
|
|
|
* Evaluate the given byte buffer in the scope of the current global of cx.
|
|
|
|
*/
|
2014-04-01 10:34:39 +00:00
|
|
|
extern JS_PUBLIC_API(bool)
|
2015-03-14 05:36:16 +00:00
|
|
|
Evaluate(JSContext *cx, const ReadOnlyCompileOptions &options,
|
2014-04-01 10:34:39 +00:00
|
|
|
const char *bytes, size_t length, JS::MutableHandleValue rval);
|
|
|
|
|
2015-03-14 05:36:16 +00:00
|
|
|
/*
|
|
|
|
* Evaluate the given file in the scope of the current global of cx.
|
|
|
|
*/
|
2014-04-01 10:34:39 +00:00
|
|
|
extern JS_PUBLIC_API(bool)
|
2015-03-14 05:36:16 +00:00
|
|
|
Evaluate(JSContext *cx, const ReadOnlyCompileOptions &options,
|
2014-04-01 10:34:39 +00:00
|
|
|
const char *filename, JS::MutableHandleValue rval);
|
|
|
|
|
2012-07-26 00:23:04 +00:00
|
|
|
} /* namespace JS */
|
|
|
|
|
2013-08-08 22:53:04 +00:00
|
|
|
extern JS_PUBLIC_API(bool)
|
2014-02-13 15:33:04 +00:00
|
|
|
JS_CallFunction(JSContext *cx, JS::HandleObject obj, JS::HandleFunction fun,
|
|
|
|
const JS::HandleValueArray& args, JS::MutableHandleValue rval);
|
1998-03-28 02:44:41 +00:00
|
|
|
|
2013-08-08 22:53:04 +00:00
|
|
|
extern JS_PUBLIC_API(bool)
|
2014-02-13 15:33:04 +00:00
|
|
|
JS_CallFunctionName(JSContext *cx, JS::HandleObject obj, const char *name,
|
|
|
|
const JS::HandleValueArray& args, JS::MutableHandleValue rval);
|
1998-03-28 02:44:41 +00:00
|
|
|
|
2013-08-08 22:53:04 +00:00
|
|
|
extern JS_PUBLIC_API(bool)
|
2014-02-13 15:33:04 +00:00
|
|
|
JS_CallFunctionValue(JSContext *cx, JS::HandleObject obj, JS::HandleValue fval,
|
|
|
|
const JS::HandleValueArray& args, JS::MutableHandleValue rval);
|
1998-03-28 02:44:41 +00:00
|
|
|
|
2010-10-12 18:50:03 +00:00
|
|
|
namespace JS {
|
|
|
|
|
|
|
|
static inline bool
|
2014-02-13 15:33:04 +00:00
|
|
|
Call(JSContext *cx, JS::HandleObject thisObj, JS::HandleFunction fun,
|
|
|
|
const JS::HandleValueArray &args, MutableHandleValue rval)
|
2013-07-24 07:40:01 +00:00
|
|
|
{
|
2014-02-13 15:33:04 +00:00
|
|
|
return !!JS_CallFunction(cx, thisObj, fun, args, rval);
|
2010-10-12 18:50:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool
|
2014-02-13 15:33:04 +00:00
|
|
|
Call(JSContext *cx, JS::HandleObject thisObj, const char *name, const JS::HandleValueArray& args,
|
2014-01-15 10:31:00 +00:00
|
|
|
MutableHandleValue rval)
|
2013-07-24 07:40:01 +00:00
|
|
|
{
|
2014-02-13 15:33:04 +00:00
|
|
|
return !!JS_CallFunctionName(cx, thisObj, name, args, rval);
|
2010-10-12 18:50:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool
|
2014-02-13 15:33:04 +00:00
|
|
|
Call(JSContext *cx, JS::HandleObject thisObj, JS::HandleValue fun, const JS::HandleValueArray& args,
|
2014-01-15 10:31:00 +00:00
|
|
|
MutableHandleValue rval)
|
2013-07-24 07:40:01 +00:00
|
|
|
{
|
2014-02-13 15:33:04 +00:00
|
|
|
return !!JS_CallFunctionValue(cx, thisObj, fun, args, rval);
|
2010-10-12 18:50:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
extern JS_PUBLIC_API(bool)
|
2014-02-13 15:33:04 +00:00
|
|
|
Call(JSContext *cx, JS::HandleValue thisv, JS::HandleValue fun, const JS::HandleValueArray& args,
|
2014-02-11 10:59:16 +00:00
|
|
|
MutableHandleValue rval);
|
2010-10-12 18:50:03 +00:00
|
|
|
|
|
|
|
static inline bool
|
2014-02-13 15:33:04 +00:00
|
|
|
Call(JSContext *cx, JS::HandleValue thisv, JS::HandleObject funObj, const JS::HandleValueArray& args,
|
2014-01-15 10:31:00 +00:00
|
|
|
MutableHandleValue rval)
|
2013-07-24 07:40:01 +00:00
|
|
|
{
|
2014-10-01 17:17:51 +00:00
|
|
|
MOZ_ASSERT(funObj);
|
2014-02-13 15:33:04 +00:00
|
|
|
JS::RootedValue fun(cx, JS::ObjectValue(*funObj));
|
|
|
|
return Call(cx, thisv, fun, args, rval);
|
2010-10-12 18:50:03 +00:00
|
|
|
}
|
|
|
|
|
2014-07-01 00:50:58 +00:00
|
|
|
extern JS_PUBLIC_API(bool)
|
|
|
|
Construct(JSContext *cx, JS::HandleValue fun,
|
|
|
|
const JS::HandleValueArray& args,
|
|
|
|
MutableHandleValue rval);
|
|
|
|
|
2011-10-04 14:06:54 +00:00
|
|
|
} /* namespace JS */
|
2010-10-12 18:50:03 +00:00
|
|
|
|
2008-01-03 09:28:40 +00:00
|
|
|
/*
|
2014-03-10 21:28:43 +00:00
|
|
|
* These functions allow setting an interrupt callback that will be called
|
2012-02-24 11:03:28 +00:00
|
|
|
* from the JS thread some time after any thread triggered the callback using
|
2014-03-10 21:28:43 +00:00
|
|
|
* JS_RequestInterruptCallback(rt).
|
2009-07-28 01:40:12 +00:00
|
|
|
*
|
2012-02-24 11:03:28 +00:00
|
|
|
* To schedule the GC and for other activities the engine internally triggers
|
2014-03-10 21:28:43 +00:00
|
|
|
* interrupt callbacks. The embedding should thus not rely on callbacks being
|
2012-02-24 11:03:28 +00:00
|
|
|
* triggered through the external API only.
|
2009-07-28 01:40:12 +00:00
|
|
|
*
|
2009-02-10 11:45:36 +00:00
|
|
|
* Important note: Additional callbacks can occur inside the callback handler
|
|
|
|
* if it re-enters the JS engine. The embedding must ensure that the callback
|
|
|
|
* is disconnected before attempting such re-entry.
|
2008-01-03 09:28:40 +00:00
|
|
|
*/
|
2014-03-10 21:28:43 +00:00
|
|
|
extern JS_PUBLIC_API(JSInterruptCallback)
|
|
|
|
JS_SetInterruptCallback(JSRuntime *rt, JSInterruptCallback callback);
|
2009-01-14 17:23:51 +00:00
|
|
|
|
2014-03-10 21:28:43 +00:00
|
|
|
extern JS_PUBLIC_API(JSInterruptCallback)
|
|
|
|
JS_GetInterruptCallback(JSRuntime *rt);
|
2009-01-14 17:23:51 +00:00
|
|
|
|
|
|
|
extern JS_PUBLIC_API(void)
|
2014-03-10 21:28:43 +00:00
|
|
|
JS_RequestInterruptCallback(JSRuntime *rt);
|
2009-02-20 12:47:46 +00:00
|
|
|
|
2013-08-08 22:53:04 +00:00
|
|
|
extern JS_PUBLIC_API(bool)
|
1998-03-28 02:44:41 +00:00
|
|
|
JS_IsRunning(JSContext *cx);
|
|
|
|
|
2007-04-13 19:20:22 +00:00
|
|
|
/*
|
|
|
|
* Saving and restoring frame chains.
|
|
|
|
*
|
2007-05-04 18:34:56 +00:00
|
|
|
* These two functions are used to set aside cx's call stack while that stack
|
|
|
|
* is inactive. After a call to JS_SaveFrameChain, it looks as if there is no
|
2007-04-13 19:20:22 +00:00
|
|
|
* code running on cx. Before calling JS_RestoreFrameChain, cx's call stack
|
|
|
|
* must be balanced and all nested calls to JS_SaveFrameChain must have had
|
|
|
|
* matching JS_RestoreFrameChain calls.
|
|
|
|
*
|
2011-05-13 15:56:26 +00:00
|
|
|
* JS_SaveFrameChain deals with cx not having any code running on it.
|
2007-04-13 19:20:22 +00:00
|
|
|
*/
|
2013-08-08 22:53:04 +00:00
|
|
|
extern JS_PUBLIC_API(bool)
|
2007-04-13 19:20:22 +00:00
|
|
|
JS_SaveFrameChain(JSContext *cx);
|
|
|
|
|
|
|
|
extern JS_PUBLIC_API(void)
|
2011-05-13 15:56:26 +00:00
|
|
|
JS_RestoreFrameChain(JSContext *cx);
|
2007-04-13 19:20:22 +00:00
|
|
|
|
2015-03-06 15:50:28 +00:00
|
|
|
namespace JS {
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This class can be used to store a pointer to the youngest frame of a saved
|
|
|
|
* stack in the specified JSContext. This reference will be picked up by any new
|
|
|
|
* calls performed until the class is destroyed, with the specified asyncCause,
|
|
|
|
* that must not be empty.
|
|
|
|
*
|
|
|
|
* Any stack capture initiated during these new calls will go through the async
|
|
|
|
* stack instead of the current stack.
|
|
|
|
*
|
|
|
|
* Capturing the stack before a new call is performed will not be affected.
|
|
|
|
*
|
|
|
|
* The provided chain of SavedFrame objects can live in any compartment,
|
|
|
|
* although it will be copied to the compartment where the stack is captured.
|
|
|
|
*/
|
|
|
|
class MOZ_STACK_CLASS JS_PUBLIC_API(AutoSetAsyncStackForNewCalls)
|
|
|
|
{
|
|
|
|
JSContext *cx;
|
|
|
|
RootedObject oldAsyncStack;
|
|
|
|
RootedString oldAsyncCause;
|
|
|
|
|
|
|
|
public:
|
|
|
|
// The stack parameter cannot be null by design, because it would be
|
|
|
|
// ambiguous whether that would clear any scheduled async stack and make the
|
|
|
|
// normal stack reappear in the new call, or just keep the async stack
|
|
|
|
// already scheduled for the new call, if any.
|
|
|
|
AutoSetAsyncStackForNewCalls(JSContext *cx, HandleObject stack,
|
|
|
|
HandleString asyncCause);
|
|
|
|
~AutoSetAsyncStackForNewCalls();
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
1998-03-28 02:44:41 +00:00
|
|
|
/************************************************************************/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Strings.
|
2000-05-14 23:00:51 +00:00
|
|
|
*
|
2010-12-10 11:50:50 +00:00
|
|
|
* NB: JS_NewUCString takes ownership of bytes on success, avoiding a copy;
|
|
|
|
* but on error (signified by null return), it leaves chars owned by the
|
|
|
|
* caller. So the caller must free bytes in the error case, if it has no use
|
|
|
|
* for them. In contrast, all the JS_New*StringCopy* functions do not take
|
|
|
|
* ownership of the character memory passed to them -- they copy it.
|
1998-03-28 02:44:41 +00:00
|
|
|
*/
|
1998-04-24 00:31:11 +00:00
|
|
|
extern JS_PUBLIC_API(JSString *)
|
1998-03-28 02:44:41 +00:00
|
|
|
JS_NewStringCopyN(JSContext *cx, const char *s, size_t n);
|
|
|
|
|
1998-04-24 00:31:11 +00:00
|
|
|
extern JS_PUBLIC_API(JSString *)
|
1998-03-28 02:44:41 +00:00
|
|
|
JS_NewStringCopyZ(JSContext *cx, const char *s);
|
|
|
|
|
2010-12-03 08:24:17 +00:00
|
|
|
extern JS_PUBLIC_API(JSString *)
|
2013-09-17 01:33:40 +00:00
|
|
|
JS_InternJSString(JSContext *cx, JS::HandleString str);
|
2010-12-03 08:24:17 +00:00
|
|
|
|
2012-07-31 19:26:14 +00:00
|
|
|
extern JS_PUBLIC_API(JSString *)
|
|
|
|
JS_InternStringN(JSContext *cx, const char *s, size_t length);
|
|
|
|
|
1998-04-24 00:31:11 +00:00
|
|
|
extern JS_PUBLIC_API(JSString *)
|
1998-03-28 02:44:41 +00:00
|
|
|
JS_InternString(JSContext *cx, const char *s);
|
|
|
|
|
1998-04-24 00:31:11 +00:00
|
|
|
extern JS_PUBLIC_API(JSString *)
|
2014-07-22 04:43:21 +00:00
|
|
|
JS_NewUCString(JSContext *cx, char16_t *chars, size_t length);
|
1998-03-28 02:44:41 +00:00
|
|
|
|
1998-04-24 00:31:11 +00:00
|
|
|
extern JS_PUBLIC_API(JSString *)
|
2014-07-22 04:43:21 +00:00
|
|
|
JS_NewUCStringCopyN(JSContext *cx, const char16_t *s, size_t n);
|
1998-03-28 02:44:41 +00:00
|
|
|
|
1998-04-24 00:31:11 +00:00
|
|
|
extern JS_PUBLIC_API(JSString *)
|
2014-07-22 04:43:21 +00:00
|
|
|
JS_NewUCStringCopyZ(JSContext *cx, const char16_t *s);
|
1998-03-28 02:44:41 +00:00
|
|
|
|
1998-04-24 00:31:11 +00:00
|
|
|
extern JS_PUBLIC_API(JSString *)
|
2014-07-22 04:43:21 +00:00
|
|
|
JS_InternUCStringN(JSContext *cx, const char16_t *s, size_t length);
|
1998-04-24 00:31:11 +00:00
|
|
|
|
|
|
|
extern JS_PUBLIC_API(JSString *)
|
2014-07-22 04:43:21 +00:00
|
|
|
JS_InternUCString(JSContext *cx, const char16_t *s);
|
1998-03-28 02:44:41 +00:00
|
|
|
|
2013-08-08 22:53:04 +00:00
|
|
|
extern JS_PUBLIC_API(bool)
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-09 03:54:10 +00:00
|
|
|
JS_CompareStrings(JSContext *cx, JSString *str1, JSString *str2, int32_t *result);
|
2010-12-03 08:24:17 +00:00
|
|
|
|
2013-08-08 22:53:04 +00:00
|
|
|
extern JS_PUBLIC_API(bool)
|
|
|
|
JS_StringEqualsAscii(JSContext *cx, JSString *str, const char *asciiBytes, bool *match);
|
2010-12-03 08:24:17 +00:00
|
|
|
|
|
|
|
extern JS_PUBLIC_API(size_t)
|
|
|
|
JS_PutEscapedString(JSContext *cx, char *buffer, size_t size, JSString *str, char quote);
|
|
|
|
|
2013-08-08 22:53:04 +00:00
|
|
|
extern JS_PUBLIC_API(bool)
|
2010-12-03 08:24:17 +00:00
|
|
|
JS_FileEscapedString(FILE *fp, JSString *str, char quote);
|
|
|
|
|
2010-10-28 15:15:53 +00:00
|
|
|
/*
|
2010-12-03 08:24:17 +00:00
|
|
|
* Extracting string characters and length.
|
|
|
|
*
|
|
|
|
* While getting the length of a string is infallible, getting the chars can
|
|
|
|
* fail. As indicated by the lack of a JSContext parameter, there are two
|
|
|
|
* special cases where getting the chars is infallible:
|
|
|
|
*
|
|
|
|
* The first case is interned strings, i.e., strings from JS_InternString or
|
2014-07-14 20:19:36 +00:00
|
|
|
* JSID_TO_STRING(id), using JS_GetLatin1InternedStringChars or
|
|
|
|
* JS_GetTwoByteInternedStringChars.
|
2010-12-03 08:24:17 +00:00
|
|
|
*
|
|
|
|
* The second case is "flat" strings that have been explicitly prepared in a
|
|
|
|
* fallible context by JS_FlattenString. To catch errors, a separate opaque
|
|
|
|
* JSFlatString type is returned by JS_FlattenString and expected by
|
|
|
|
* JS_GetFlatStringChars. Note, though, that this is purely a syntactic
|
|
|
|
* distinction: the input and output of JS_FlattenString are the same actual
|
2014-07-14 20:19:36 +00:00
|
|
|
* GC-thing. If a JSString is known to be flat, JS_ASSERT_STRING_IS_FLAT can be
|
|
|
|
* used to make a debug-checked cast. Example:
|
2010-12-03 08:24:17 +00:00
|
|
|
*
|
|
|
|
* // in a fallible context
|
|
|
|
* JSFlatString *fstr = JS_FlattenString(cx, str);
|
|
|
|
* if (!fstr)
|
2013-08-07 06:59:54 +00:00
|
|
|
* return false;
|
2014-10-01 17:17:51 +00:00
|
|
|
* MOZ_ASSERT(fstr == JS_ASSERT_STRING_IS_FLAT(str));
|
2010-12-03 08:24:17 +00:00
|
|
|
*
|
|
|
|
* // in an infallible context, for the same 'str'
|
2014-07-14 20:19:36 +00:00
|
|
|
* AutoCheckCannotGC nogc;
|
2014-07-22 04:43:21 +00:00
|
|
|
* const char16_t *chars = JS_GetTwoByteFlatStringChars(nogc, fstr)
|
2014-10-01 17:17:51 +00:00
|
|
|
* MOZ_ASSERT(chars);
|
2010-12-03 08:24:17 +00:00
|
|
|
*
|
2014-07-14 20:19:36 +00:00
|
|
|
* Flat strings and interned strings are always null-terminated, so
|
|
|
|
* JS_FlattenString can be used to get a null-terminated string.
|
|
|
|
*
|
|
|
|
* Additionally, string characters are stored as either Latin1Char (8-bit)
|
2014-07-22 04:43:21 +00:00
|
|
|
* or char16_t (16-bit). Clients can use JS_StringHasLatin1Chars and can then
|
2014-07-14 20:19:36 +00:00
|
|
|
* call either the Latin1* or TwoByte* functions. Some functions like
|
|
|
|
* JS_CopyStringChars and JS_GetStringCharAt accept both Latin1 and TwoByte
|
|
|
|
* strings.
|
2010-10-28 15:15:53 +00:00
|
|
|
*/
|
1998-03-28 02:44:41 +00:00
|
|
|
|
1998-04-24 00:31:11 +00:00
|
|
|
extern JS_PUBLIC_API(size_t)
|
1998-03-28 02:44:41 +00:00
|
|
|
JS_GetStringLength(JSString *str);
|
|
|
|
|
2014-07-14 20:19:36 +00:00
|
|
|
extern JS_PUBLIC_API(bool)
|
|
|
|
JS_StringIsFlat(JSString *str);
|
|
|
|
|
2014-07-02 11:04:14 +00:00
|
|
|
/* Returns true iff the string's characters are stored as Latin1. */
|
|
|
|
extern JS_PUBLIC_API(bool)
|
|
|
|
JS_StringHasLatin1Chars(JSString *str);
|
|
|
|
|
2014-07-02 13:45:04 +00:00
|
|
|
extern JS_PUBLIC_API(const JS::Latin1Char *)
|
|
|
|
JS_GetLatin1StringCharsAndLength(JSContext *cx, const JS::AutoCheckCannotGC &nogc, JSString *str,
|
|
|
|
size_t *length);
|
|
|
|
|
2014-07-22 04:43:21 +00:00
|
|
|
extern JS_PUBLIC_API(const char16_t *)
|
2014-07-02 11:04:14 +00:00
|
|
|
JS_GetTwoByteStringCharsAndLength(JSContext *cx, const JS::AutoCheckCannotGC &nogc, JSString *str,
|
|
|
|
size_t *length);
|
|
|
|
|
2014-07-10 15:36:31 +00:00
|
|
|
extern JS_PUBLIC_API(bool)
|
2014-07-22 04:43:21 +00:00
|
|
|
JS_GetStringCharAt(JSContext *cx, JSString *str, size_t index, char16_t *res);
|
2014-07-10 15:36:31 +00:00
|
|
|
|
2014-07-22 04:43:21 +00:00
|
|
|
extern JS_PUBLIC_API(char16_t)
|
2014-07-10 15:36:31 +00:00
|
|
|
JS_GetFlatStringCharAt(JSFlatString *str, size_t index);
|
|
|
|
|
2014-07-22 04:43:21 +00:00
|
|
|
extern JS_PUBLIC_API(const char16_t *)
|
2014-07-10 15:36:31 +00:00
|
|
|
JS_GetTwoByteExternalStringChars(JSString *str);
|
|
|
|
|
|
|
|
extern JS_PUBLIC_API(bool)
|
2014-07-22 04:43:21 +00:00
|
|
|
JS_CopyStringChars(JSContext *cx, mozilla::Range<char16_t> dest, JSString *str);
|
2014-07-10 15:36:31 +00:00
|
|
|
|
2014-07-14 20:19:36 +00:00
|
|
|
extern JS_PUBLIC_API(const JS::Latin1Char *)
|
|
|
|
JS_GetLatin1InternedStringChars(const JS::AutoCheckCannotGC &nogc, JSString *str);
|
2009-10-02 17:42:02 +00:00
|
|
|
|
2014-07-22 04:43:21 +00:00
|
|
|
extern JS_PUBLIC_API(const char16_t *)
|
2014-07-14 20:19:36 +00:00
|
|
|
JS_GetTwoByteInternedStringChars(const JS::AutoCheckCannotGC &nogc, JSString *str);
|
1998-03-28 02:44:41 +00:00
|
|
|
|
2010-12-03 08:24:17 +00:00
|
|
|
extern JS_PUBLIC_API(JSFlatString *)
|
|
|
|
JS_FlattenString(JSContext *cx, JSString *str);
|
2010-10-28 15:15:53 +00:00
|
|
|
|
2014-07-14 20:19:36 +00:00
|
|
|
extern JS_PUBLIC_API(const JS::Latin1Char *)
|
|
|
|
JS_GetLatin1FlatStringChars(const JS::AutoCheckCannotGC &nogc, JSFlatString *str);
|
|
|
|
|
2014-07-22 04:43:21 +00:00
|
|
|
extern JS_PUBLIC_API(const char16_t *)
|
2014-07-14 20:19:36 +00:00
|
|
|
JS_GetTwoByteFlatStringChars(const JS::AutoCheckCannotGC &nogc, JSFlatString *str);
|
2010-12-03 08:24:17 +00:00
|
|
|
|
2014-01-25 04:14:56 +00:00
|
|
|
static MOZ_ALWAYS_INLINE JSFlatString *
|
2010-12-03 08:24:17 +00:00
|
|
|
JSID_TO_FLAT_STRING(jsid id)
|
|
|
|
{
|
2014-10-01 17:17:51 +00:00
|
|
|
MOZ_ASSERT(JSID_IS_STRING(id));
|
2010-12-03 08:24:17 +00:00
|
|
|
return (JSFlatString *)(JSID_BITS(id));
|
|
|
|
}
|
|
|
|
|
2014-01-25 04:14:56 +00:00
|
|
|
static MOZ_ALWAYS_INLINE JSFlatString *
|
2010-12-03 08:24:17 +00:00
|
|
|
JS_ASSERT_STRING_IS_FLAT(JSString *str)
|
|
|
|
{
|
2014-10-01 17:17:51 +00:00
|
|
|
MOZ_ASSERT(JS_StringIsFlat(str));
|
2010-12-03 08:24:17 +00:00
|
|
|
return (JSFlatString *)str;
|
|
|
|
}
|
|
|
|
|
2014-01-25 04:14:56 +00:00
|
|
|
static MOZ_ALWAYS_INLINE JSString *
|
2010-12-03 08:24:17 +00:00
|
|
|
JS_FORGET_STRING_FLATNESS(JSFlatString *fstr)
|
|
|
|
{
|
|
|
|
return (JSString *)fstr;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Additional APIs that avoid fallibility when given a flat string.
|
|
|
|
*/
|
2010-10-28 15:15:53 +00:00
|
|
|
|
2013-08-08 22:53:04 +00:00
|
|
|
extern JS_PUBLIC_API(bool)
|
2010-12-03 08:24:17 +00:00
|
|
|
JS_FlatStringEqualsAscii(JSFlatString *str, const char *asciiBytes);
|
|
|
|
|
|
|
|
extern JS_PUBLIC_API(size_t)
|
|
|
|
JS_PutEscapedFlatString(char *buffer, size_t size, JSFlatString *str, char quote);
|
2010-10-28 15:15:53 +00:00
|
|
|
|
2001-10-25 00:26:38 +00:00
|
|
|
/*
|
|
|
|
* Create a dependent string, i.e., a string that owns no character storage,
|
|
|
|
* but that refers to a slice of another string's chars. Dependent strings
|
|
|
|
* are mutable by definition, so the thread safety comments above apply.
|
|
|
|
*/
|
|
|
|
extern JS_PUBLIC_API(JSString *)
|
2013-09-17 01:33:40 +00:00
|
|
|
JS_NewDependentString(JSContext *cx, JS::HandleString str, size_t start,
|
2001-10-25 00:26:38 +00:00
|
|
|
size_t length);
|
|
|
|
|
|
|
|
/*
|
2010-07-17 00:41:22 +00:00
|
|
|
* Concatenate two strings, possibly resulting in a rope.
|
|
|
|
* See above for thread safety comments.
|
2001-10-25 00:26:38 +00:00
|
|
|
*/
|
|
|
|
extern JS_PUBLIC_API(JSString *)
|
2013-09-17 01:33:40 +00:00
|
|
|
JS_ConcatStrings(JSContext *cx, JS::HandleString left, JS::HandleString right);
|
2001-10-25 00:26:38 +00:00
|
|
|
|
2005-11-05 01:06:30 +00:00
|
|
|
/*
|
2012-10-29 20:55:17 +00:00
|
|
|
* For JS_DecodeBytes, set *dstlenp to the size of the destination buffer before
|
2014-07-22 04:43:21 +00:00
|
|
|
* the call; on return, *dstlenp contains the number of characters actually
|
|
|
|
* stored. To determine the necessary destination buffer size, make a sizing
|
|
|
|
* call that passes nullptr for dst.
|
2005-12-03 02:31:21 +00:00
|
|
|
*
|
|
|
|
* On errors, the functions report the error. In that case, *dstlenp contains
|
2013-10-07 16:42:55 +00:00
|
|
|
* the number of characters or bytes transferred so far. If cx is nullptr, no
|
2013-08-07 06:59:54 +00:00
|
|
|
* error is reported on failure, and the functions simply return false.
|
2005-12-03 02:31:21 +00:00
|
|
|
*
|
2014-07-22 04:43:21 +00:00
|
|
|
* NB: This function does not store an additional zero byte or char16_t after the
|
2005-12-03 02:31:21 +00:00
|
|
|
* transcoded string.
|
2005-11-05 01:06:30 +00:00
|
|
|
*/
|
2013-08-08 22:53:04 +00:00
|
|
|
JS_PUBLIC_API(bool)
|
2014-07-22 04:43:21 +00:00
|
|
|
JS_DecodeBytes(JSContext *cx, const char *src, size_t srclen, char16_t *dst,
|
2005-12-03 02:31:21 +00:00
|
|
|
size_t *dstlenp);
|
2005-11-05 01:06:30 +00:00
|
|
|
|
2007-12-11 10:09:58 +00:00
|
|
|
/*
|
|
|
|
* A variation on JS_EncodeCharacters where a null terminated string is
|
|
|
|
* returned that you are expected to call JS_free on when done.
|
|
|
|
*/
|
|
|
|
JS_PUBLIC_API(char *)
|
2013-04-16 21:33:00 +00:00
|
|
|
JS_EncodeString(JSContext *cx, JSString *str);
|
2007-12-11 10:09:58 +00:00
|
|
|
|
2013-02-22 02:58:52 +00:00
|
|
|
/*
|
|
|
|
* Same behavior as JS_EncodeString(), but encode into UTF-8 string
|
|
|
|
*/
|
|
|
|
JS_PUBLIC_API(char *)
|
2014-04-02 14:28:03 +00:00
|
|
|
JS_EncodeStringToUTF8(JSContext *cx, JS::HandleString str);
|
2013-02-22 02:58:52 +00:00
|
|
|
|
2010-11-08 12:17:31 +00:00
|
|
|
/*
|
|
|
|
* Get number of bytes in the string encoding (without accounting for a
|
|
|
|
* terminating zero bytes. The function returns (size_t) -1 if the string
|
|
|
|
* can not be encoded into bytes and reports an error using cx accordingly.
|
|
|
|
*/
|
|
|
|
JS_PUBLIC_API(size_t)
|
|
|
|
JS_GetStringEncodingLength(JSContext *cx, JSString *str);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Encode string into a buffer. The function does not stores an additional
|
|
|
|
* zero byte. The function returns (size_t) -1 if the string can not be
|
|
|
|
* encoded into bytes with no error reported. Otherwise it returns the number
|
|
|
|
* of bytes that are necessary to encode the string. If that exceeds the
|
|
|
|
* length parameter, the string will be cut and only length bytes will be
|
|
|
|
* written into the buffer.
|
|
|
|
*/
|
|
|
|
JS_PUBLIC_API(size_t)
|
2012-11-09 17:45:25 +00:00
|
|
|
JS_EncodeStringToBuffer(JSContext *cx, JSString *str, char *buffer, size_t length);
|
2010-11-08 12:17:31 +00:00
|
|
|
|
2012-12-27 17:20:22 +00:00
|
|
|
class JSAutoByteString
|
|
|
|
{
|
2010-11-11 20:40:29 +00:00
|
|
|
public:
|
2012-12-27 17:20:22 +00:00
|
|
|
JSAutoByteString(JSContext *cx, JSString *str
|
2012-12-27 17:20:22 +00:00
|
|
|
MOZ_GUARD_OBJECT_NOTIFIER_PARAM)
|
2012-12-27 17:20:22 +00:00
|
|
|
: mBytes(JS_EncodeString(cx, str))
|
|
|
|
{
|
2014-10-01 17:17:51 +00:00
|
|
|
MOZ_ASSERT(cx);
|
2012-12-27 17:20:22 +00:00
|
|
|
MOZ_GUARD_OBJECT_NOTIFIER_INIT;
|
2010-11-11 20:40:29 +00:00
|
|
|
}
|
|
|
|
|
2014-06-04 22:22:10 +00:00
|
|
|
explicit JSAutoByteString(MOZ_GUARD_OBJECT_NOTIFIER_ONLY_PARAM)
|
2013-10-07 16:42:55 +00:00
|
|
|
: mBytes(nullptr)
|
2012-12-27 17:20:22 +00:00
|
|
|
{
|
|
|
|
MOZ_GUARD_OBJECT_NOTIFIER_INIT;
|
2010-11-11 20:40:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
~JSAutoByteString() {
|
2012-08-31 22:01:33 +00:00
|
|
|
js_free(mBytes);
|
2010-11-11 20:40:29 +00:00
|
|
|
}
|
|
|
|
|
2010-12-09 10:22:15 +00:00
|
|
|
/* Take ownership of the given byte array. */
|
|
|
|
void initBytes(char *bytes) {
|
2014-10-01 17:17:51 +00:00
|
|
|
MOZ_ASSERT(!mBytes);
|
2010-12-09 10:22:15 +00:00
|
|
|
mBytes = bytes;
|
|
|
|
}
|
|
|
|
|
2013-02-21 09:48:17 +00:00
|
|
|
char *encodeLatin1(JSContext *cx, JSString *str) {
|
2014-10-01 17:17:51 +00:00
|
|
|
MOZ_ASSERT(!mBytes);
|
|
|
|
MOZ_ASSERT(cx);
|
2010-11-11 20:40:29 +00:00
|
|
|
mBytes = JS_EncodeString(cx, str);
|
|
|
|
return mBytes;
|
|
|
|
}
|
|
|
|
|
2013-09-11 23:42:09 +00:00
|
|
|
char *encodeLatin1(js::ExclusiveContext *cx, JSString *str);
|
2013-07-10 15:29:52 +00:00
|
|
|
|
2014-04-02 14:28:03 +00:00
|
|
|
char *encodeUtf8(JSContext *cx, JS::HandleString str) {
|
2014-10-01 17:17:51 +00:00
|
|
|
MOZ_ASSERT(!mBytes);
|
|
|
|
MOZ_ASSERT(cx);
|
2013-02-22 02:58:52 +00:00
|
|
|
mBytes = JS_EncodeStringToUTF8(cx, str);
|
|
|
|
return mBytes;
|
|
|
|
}
|
|
|
|
|
2010-11-11 20:40:29 +00:00
|
|
|
void clear() {
|
2012-08-31 22:01:33 +00:00
|
|
|
js_free(mBytes);
|
2013-10-07 16:42:55 +00:00
|
|
|
mBytes = nullptr;
|
2010-11-11 20:40:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
char *ptr() const {
|
|
|
|
return mBytes;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool operator!() const {
|
|
|
|
return !mBytes;
|
|
|
|
}
|
|
|
|
|
2013-02-22 02:58:52 +00:00
|
|
|
size_t length() const {
|
|
|
|
if (!mBytes)
|
|
|
|
return 0;
|
|
|
|
return strlen(mBytes);
|
|
|
|
}
|
|
|
|
|
2010-11-11 20:40:29 +00:00
|
|
|
private:
|
|
|
|
char *mBytes;
|
2012-12-27 17:20:22 +00:00
|
|
|
MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER
|
2010-11-11 20:40:29 +00:00
|
|
|
|
|
|
|
/* Copy and assignment are not supported. */
|
|
|
|
JSAutoByteString(const JSAutoByteString &another);
|
|
|
|
JSAutoByteString &operator=(const JSAutoByteString &another);
|
|
|
|
};
|
|
|
|
|
2014-06-21 18:54:22 +00:00
|
|
|
namespace JS {
|
|
|
|
|
|
|
|
extern JS_PUBLIC_API(JSAddonId *)
|
|
|
|
NewAddonId(JSContext *cx, JS::HandleString str);
|
|
|
|
|
|
|
|
extern JS_PUBLIC_API(JSString *)
|
|
|
|
StringOfAddonId(JSAddonId *id);
|
|
|
|
|
2014-06-21 18:54:36 +00:00
|
|
|
extern JS_PUBLIC_API(JSAddonId *)
|
|
|
|
AddonIdOfObject(JSObject *obj);
|
|
|
|
|
2014-06-21 18:54:22 +00:00
|
|
|
} // namespace JS
|
|
|
|
|
2014-06-23 15:55:51 +00:00
|
|
|
/************************************************************************/
|
|
|
|
/*
|
|
|
|
* Symbols
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace JS {
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Create a new Symbol with the given description. This function never returns
|
|
|
|
* a Symbol that is in the Runtime-wide symbol registry.
|
|
|
|
*
|
|
|
|
* If description is null, the new Symbol's [[Description]] attribute is
|
|
|
|
* undefined.
|
|
|
|
*/
|
|
|
|
JS_PUBLIC_API(Symbol *)
|
|
|
|
NewSymbol(JSContext *cx, HandleString description);
|
|
|
|
|
2014-06-23 15:56:49 +00:00
|
|
|
/*
|
|
|
|
* Symbol.for as specified in ES6.
|
|
|
|
*
|
|
|
|
* Get a Symbol with the description 'key' from the Runtime-wide symbol registry.
|
|
|
|
* If there is not already a Symbol with that description in the registry, a new
|
|
|
|
* Symbol is created and registered. 'key' must not be null.
|
|
|
|
*/
|
|
|
|
JS_PUBLIC_API(Symbol *)
|
|
|
|
GetSymbolFor(JSContext *cx, HandleString key);
|
|
|
|
|
2014-06-23 15:55:51 +00:00
|
|
|
/*
|
|
|
|
* Get the [[Description]] attribute of the given symbol.
|
|
|
|
*
|
|
|
|
* This function is infallible. If it returns null, that means the symbol's
|
|
|
|
* [[Description]] is undefined.
|
|
|
|
*/
|
|
|
|
JS_PUBLIC_API(JSString *)
|
|
|
|
GetSymbolDescription(HandleSymbol symbol);
|
|
|
|
|
2014-06-23 15:56:49 +00:00
|
|
|
/* Well-known symbols. */
|
2015-01-25 22:22:07 +00:00
|
|
|
enum class SymbolCode : uint32_t {
|
2014-06-23 15:56:49 +00:00
|
|
|
iterator, // well-known Symbol.iterator
|
|
|
|
InSymbolRegistry = 0xfffffffe, // created by Symbol.for() or JS::GetSymbolFor()
|
|
|
|
UniqueSymbol = 0xffffffff // created by Symbol() or JS::NewSymbol()
|
2015-01-25 22:22:07 +00:00
|
|
|
};
|
2014-06-23 15:56:49 +00:00
|
|
|
|
|
|
|
/* For use in loops that iterate over the well-known symbols. */
|
|
|
|
const size_t WellKnownSymbolLimit = 1;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Return the SymbolCode telling what sort of symbol `symbol` is.
|
|
|
|
*
|
|
|
|
* A symbol's SymbolCode never changes once it is created.
|
|
|
|
*/
|
|
|
|
JS_PUBLIC_API(SymbolCode)
|
|
|
|
GetSymbolCode(Handle<Symbol*> symbol);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get one of the well-known symbols defined by ES6. A single set of well-known
|
|
|
|
* symbols is shared by all compartments in a JSRuntime.
|
|
|
|
*
|
|
|
|
* `which` must be in the range [0, WellKnownSymbolLimit).
|
|
|
|
*/
|
|
|
|
JS_PUBLIC_API(Symbol *)
|
|
|
|
GetWellKnownSymbol(JSContext *cx, SymbolCode which);
|
|
|
|
|
2014-07-25 23:50:48 +00:00
|
|
|
/*
|
|
|
|
* Return true if the given JSPropertySpec::name or JSFunctionSpec::name value
|
|
|
|
* is actually a symbol code and not a string. See JS_SYM_FN.
|
|
|
|
*/
|
|
|
|
inline bool
|
|
|
|
PropertySpecNameIsSymbol(const char *name)
|
|
|
|
{
|
|
|
|
uintptr_t u = reinterpret_cast<uintptr_t>(name);
|
|
|
|
return u != 0 && u - 1 < WellKnownSymbolLimit;
|
|
|
|
}
|
|
|
|
|
2014-09-18 17:30:38 +00:00
|
|
|
JS_PUBLIC_API(bool)
|
|
|
|
PropertySpecNameEqualsId(const char *name, HandleId id);
|
|
|
|
|
2014-07-25 23:50:48 +00:00
|
|
|
/*
|
|
|
|
* Create a jsid that does not need to be marked for GC.
|
|
|
|
*
|
|
|
|
* 'name' is a JSPropertySpec::name or JSFunctionSpec::name value. The
|
|
|
|
* resulting jsid, on success, is either an interned string or a well-known
|
|
|
|
* symbol; either way it is immune to GC so there is no need to visit *idp
|
|
|
|
* during GC marking.
|
|
|
|
*/
|
|
|
|
JS_PUBLIC_API(bool)
|
|
|
|
PropertySpecNameToPermanentId(JSContext *cx, const char *name, jsid *idp);
|
|
|
|
|
2014-06-23 15:55:51 +00:00
|
|
|
} /* namespace JS */
|
|
|
|
|
2008-10-01 06:13:58 +00:00
|
|
|
/************************************************************************/
|
|
|
|
/*
|
|
|
|
* JSON functions
|
|
|
|
*/
|
2014-07-22 04:43:21 +00:00
|
|
|
typedef bool (* JSONWriteCallback)(const char16_t *buf, uint32_t len, void *data);
|
2008-10-01 06:13:58 +00:00
|
|
|
|
|
|
|
/*
|
2011-03-21 18:42:14 +00:00
|
|
|
* JSON.stringify as specified by ES5.
|
2008-10-01 06:13:58 +00:00
|
|
|
*/
|
2013-08-08 22:53:04 +00:00
|
|
|
JS_PUBLIC_API(bool)
|
2013-09-17 01:33:40 +00:00
|
|
|
JS_Stringify(JSContext *cx, JS::MutableHandleValue value, JS::HandleObject replacer,
|
|
|
|
JS::HandleValue space, JSONWriteCallback callback, void *data);
|
2008-10-01 06:13:58 +00:00
|
|
|
|
|
|
|
/*
|
2011-03-21 18:42:14 +00:00
|
|
|
* JSON.parse as specified by ES5.
|
2008-10-01 06:13:58 +00:00
|
|
|
*/
|
2013-08-08 22:53:04 +00:00
|
|
|
JS_PUBLIC_API(bool)
|
2014-07-22 04:43:21 +00:00
|
|
|
JS_ParseJSON(JSContext *cx, const char16_t *chars, uint32_t len, JS::MutableHandleValue vp);
|
2011-03-21 18:42:06 +00:00
|
|
|
|
2014-07-14 13:01:32 +00:00
|
|
|
JS_PUBLIC_API(bool)
|
|
|
|
JS_ParseJSON(JSContext *cx, JS::HandleString str, JS::MutableHandleValue vp);
|
|
|
|
|
2013-08-08 22:53:04 +00:00
|
|
|
JS_PUBLIC_API(bool)
|
2014-07-22 04:43:21 +00:00
|
|
|
JS_ParseJSONWithReviver(JSContext *cx, const char16_t *chars, uint32_t len, JS::HandleValue reviver,
|
2013-09-17 01:33:40 +00:00
|
|
|
JS::MutableHandleValue vp);
|
2011-03-21 18:42:06 +00:00
|
|
|
|
2014-07-14 13:01:32 +00:00
|
|
|
JS_PUBLIC_API(bool)
|
|
|
|
JS_ParseJSONWithReviver(JSContext *cx, JS::HandleString str, JS::HandleValue reviver,
|
|
|
|
JS::MutableHandleValue vp);
|
|
|
|
|
1998-03-28 02:44:41 +00:00
|
|
|
/************************************************************************/
|
|
|
|
|
2013-01-03 18:29:09 +00:00
|
|
|
/*
|
|
|
|
* The default locale for the ECMAScript Internationalization API
|
|
|
|
* (Intl.Collator, Intl.NumberFormat, Intl.DateTimeFormat).
|
|
|
|
* Note that the Internationalization API encourages clients to
|
|
|
|
* specify their own locales.
|
|
|
|
* The locale string remains owned by the caller.
|
|
|
|
*/
|
2013-08-08 22:53:04 +00:00
|
|
|
extern JS_PUBLIC_API(bool)
|
2013-02-08 02:04:11 +00:00
|
|
|
JS_SetDefaultLocale(JSRuntime *rt, const char *locale);
|
2013-01-03 18:29:09 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Reset the default locale to OS defaults.
|
|
|
|
*/
|
|
|
|
extern JS_PUBLIC_API(void)
|
2013-02-08 02:04:11 +00:00
|
|
|
JS_ResetDefaultLocale(JSRuntime *rt);
|
2013-01-03 18:29:09 +00:00
|
|
|
|
2000-08-09 21:46:03 +00:00
|
|
|
/*
|
2005-12-03 02:31:21 +00:00
|
|
|
* Locale specific string conversion and error message callbacks.
|
2000-08-09 21:46:03 +00:00
|
|
|
*/
|
|
|
|
struct JSLocaleCallbacks {
|
|
|
|
JSLocaleToUpperCase localeToUpperCase;
|
|
|
|
JSLocaleToLowerCase localeToLowerCase;
|
2013-08-08 22:17:08 +00:00
|
|
|
JSLocaleCompare localeCompare; // not used #if EXPOSE_INTL_API
|
2004-06-15 16:38:43 +00:00
|
|
|
JSLocaleToUnicode localeToUnicode;
|
2000-08-09 21:46:03 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
2000-09-08 21:24:14 +00:00
|
|
|
* Establish locale callbacks. The pointer must persist as long as the
|
2013-10-07 16:42:55 +00:00
|
|
|
* JSRuntime. Passing nullptr restores the default behaviour.
|
2000-08-09 21:46:03 +00:00
|
|
|
*/
|
|
|
|
extern JS_PUBLIC_API(void)
|
2014-12-17 00:30:39 +00:00
|
|
|
JS_SetLocaleCallbacks(JSRuntime *rt, const JSLocaleCallbacks *callbacks);
|
2000-08-09 21:46:03 +00:00
|
|
|
|
2000-09-08 21:24:14 +00:00
|
|
|
/*
|
|
|
|
* Return the address of the current locale callbacks struct, which may
|
2013-10-07 16:42:55 +00:00
|
|
|
* be nullptr.
|
2000-09-08 21:24:14 +00:00
|
|
|
*/
|
2014-12-17 00:30:39 +00:00
|
|
|
extern JS_PUBLIC_API(const JSLocaleCallbacks *)
|
2013-02-08 02:04:11 +00:00
|
|
|
JS_GetLocaleCallbacks(JSRuntime *rt);
|
2000-08-09 21:46:03 +00:00
|
|
|
|
|
|
|
/************************************************************************/
|
|
|
|
|
1998-03-28 02:44:41 +00:00
|
|
|
/*
|
|
|
|
* Error reporting.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Report an exception represented by the sprintf-like conversion of format
|
|
|
|
* and its arguments. This exception message string is passed to a pre-set
|
2011-09-19 16:34:49 +00:00
|
|
|
* JSErrorReporter function (set by JS_SetErrorReporter).
|
1998-03-28 02:44:41 +00:00
|
|
|
*/
|
1998-04-24 00:31:11 +00:00
|
|
|
extern JS_PUBLIC_API(void)
|
1998-03-28 02:44:41 +00:00
|
|
|
JS_ReportError(JSContext *cx, const char *format, ...);
|
|
|
|
|
1998-10-14 10:22:38 +00:00
|
|
|
/*
|
|
|
|
* Use an errorNumber to retrieve the format string, args are char *
|
|
|
|
*/
|
|
|
|
extern JS_PUBLIC_API(void)
|
|
|
|
JS_ReportErrorNumber(JSContext *cx, JSErrorCallback errorCallback,
|
2012-02-28 23:11:11 +00:00
|
|
|
void *userRef, const unsigned errorNumber, ...);
|
1998-10-14 10:22:38 +00:00
|
|
|
|
2012-07-18 10:36:08 +00:00
|
|
|
#ifdef va_start
|
|
|
|
extern JS_PUBLIC_API(void)
|
|
|
|
JS_ReportErrorNumberVA(JSContext *cx, JSErrorCallback errorCallback,
|
|
|
|
void *userRef, const unsigned errorNumber, va_list ap);
|
|
|
|
#endif
|
|
|
|
|
1998-10-14 10:22:38 +00:00
|
|
|
/*
|
2014-07-22 04:43:21 +00:00
|
|
|
* Use an errorNumber to retrieve the format string, args are char16_t *
|
1998-10-14 10:22:38 +00:00
|
|
|
*/
|
|
|
|
extern JS_PUBLIC_API(void)
|
|
|
|
JS_ReportErrorNumberUC(JSContext *cx, JSErrorCallback errorCallback,
|
2012-02-28 23:11:11 +00:00
|
|
|
void *userRef, const unsigned errorNumber, ...);
|
1998-10-14 10:22:38 +00:00
|
|
|
|
2012-11-06 23:23:14 +00:00
|
|
|
extern JS_PUBLIC_API(void)
|
|
|
|
JS_ReportErrorNumberUCArray(JSContext *cx, JSErrorCallback errorCallback,
|
|
|
|
void *userRef, const unsigned errorNumber,
|
2014-07-22 04:43:21 +00:00
|
|
|
const char16_t **args);
|
2012-11-06 23:23:14 +00:00
|
|
|
|
1998-10-14 10:22:38 +00:00
|
|
|
/*
|
2000-01-18 11:06:05 +00:00
|
|
|
* As above, but report a warning instead (JSREPORT_IS_WARNING(report.flags)).
|
|
|
|
* Return true if there was no error trying to issue the warning, and if the
|
|
|
|
* warning was not converted into an error due to the JSOPTION_WERROR option
|
|
|
|
* being set, false otherwise.
|
1998-10-14 10:22:38 +00:00
|
|
|
*/
|
2013-08-08 22:53:04 +00:00
|
|
|
extern JS_PUBLIC_API(bool)
|
1998-10-14 10:22:38 +00:00
|
|
|
JS_ReportWarning(JSContext *cx, const char *format, ...);
|
|
|
|
|
2013-08-08 22:53:04 +00:00
|
|
|
extern JS_PUBLIC_API(bool)
|
2012-02-28 23:11:11 +00:00
|
|
|
JS_ReportErrorFlagsAndNumber(JSContext *cx, unsigned flags,
|
2000-01-18 11:06:05 +00:00
|
|
|
JSErrorCallback errorCallback, void *userRef,
|
2012-02-28 23:11:11 +00:00
|
|
|
const unsigned errorNumber, ...);
|
2000-01-18 11:06:05 +00:00
|
|
|
|
2013-08-08 22:53:04 +00:00
|
|
|
extern JS_PUBLIC_API(bool)
|
2012-02-28 23:11:11 +00:00
|
|
|
JS_ReportErrorFlagsAndNumberUC(JSContext *cx, unsigned flags,
|
2000-01-18 11:06:05 +00:00
|
|
|
JSErrorCallback errorCallback, void *userRef,
|
2012-02-28 23:11:11 +00:00
|
|
|
const unsigned errorNumber, ...);
|
2000-01-18 11:06:05 +00:00
|
|
|
|
1998-03-28 02:44:41 +00:00
|
|
|
/*
|
|
|
|
* Complain when out of memory.
|
|
|
|
*/
|
1998-04-24 00:31:11 +00:00
|
|
|
extern JS_PUBLIC_API(void)
|
1998-03-28 02:44:41 +00:00
|
|
|
JS_ReportOutOfMemory(JSContext *cx);
|
|
|
|
|
2008-03-12 23:07:47 +00:00
|
|
|
/*
|
|
|
|
* Complain when an allocation size overflows the maximum supported limit.
|
|
|
|
*/
|
|
|
|
extern JS_PUBLIC_API(void)
|
|
|
|
JS_ReportAllocationOverflow(JSContext *cx);
|
|
|
|
|
2014-10-20 17:13:03 +00:00
|
|
|
class JSErrorReport
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
JSErrorReport()
|
|
|
|
: filename(nullptr), lineno(0), column(0), isMuted(false), linebuf(nullptr),
|
|
|
|
tokenptr(nullptr), uclinebuf(nullptr), uctokenptr(nullptr), flags(0), errorNumber(0),
|
|
|
|
ucmessage(nullptr), messageArgs(nullptr), exnType(0)
|
|
|
|
{}
|
|
|
|
|
1998-10-14 10:22:38 +00:00
|
|
|
const char *filename; /* source file name, URL, etc., or null */
|
2012-08-31 22:01:33 +00:00
|
|
|
unsigned lineno; /* source line number */
|
2014-10-20 17:13:03 +00:00
|
|
|
unsigned column; /* zero-based column index in line */
|
|
|
|
bool isMuted; /* See the comment in ReadOnlyCompileOptions. */
|
1998-10-14 10:22:38 +00:00
|
|
|
const char *linebuf; /* offending source line without final \n */
|
|
|
|
const char *tokenptr; /* pointer to error token in linebuf */
|
2014-07-22 04:43:21 +00:00
|
|
|
const char16_t *uclinebuf; /* unicode (original) line buffer */
|
|
|
|
const char16_t *uctokenptr; /* unicode (original) token pointer */
|
2012-08-31 22:01:33 +00:00
|
|
|
unsigned flags; /* error/warning, etc. */
|
|
|
|
unsigned errorNumber; /* the error number, e.g. see js.msg */
|
2014-07-22 04:43:21 +00:00
|
|
|
const char16_t *ucmessage; /* the (default) error message */
|
|
|
|
const char16_t **messageArgs; /* arguments for the error message */
|
2012-07-18 10:36:08 +00:00
|
|
|
int16_t exnType; /* One of the JSExnType constants */
|
1998-03-28 02:44:41 +00:00
|
|
|
};
|
|
|
|
|
1998-10-14 10:22:38 +00:00
|
|
|
/*
|
2000-01-18 11:06:05 +00:00
|
|
|
* JSErrorReport flag values. These may be freely composed.
|
1998-10-14 10:22:38 +00:00
|
|
|
*/
|
2000-01-18 11:06:05 +00:00
|
|
|
#define JSREPORT_ERROR 0x0 /* pseudo-flag for default case */
|
|
|
|
#define JSREPORT_WARNING 0x1 /* reported via JS_ReportWarning */
|
|
|
|
#define JSREPORT_EXCEPTION 0x2 /* exception was thrown */
|
|
|
|
#define JSREPORT_STRICT 0x4 /* error or warning due to strict option */
|
1998-10-14 10:22:38 +00:00
|
|
|
|
2009-11-19 17:23:20 +00:00
|
|
|
/*
|
|
|
|
* This condition is an error in strict mode code, a warning if
|
|
|
|
* JS_HAS_STRICT_OPTION(cx), and otherwise should not be reported at
|
|
|
|
* all. We check the strictness of the context's top frame's script;
|
|
|
|
* where that isn't appropriate, the caller should do the right checks
|
|
|
|
* itself instead of using this flag.
|
|
|
|
*/
|
|
|
|
#define JSREPORT_STRICT_MODE_ERROR 0x8
|
|
|
|
|
1998-10-14 10:22:38 +00:00
|
|
|
/*
|
|
|
|
* If JSREPORT_EXCEPTION is set, then a JavaScript-catchable exception
|
|
|
|
* has been thrown for this runtime error, and the host should ignore it.
|
|
|
|
* Exception-aware hosts should also check for JS_IsExceptionPending if
|
|
|
|
* JS_ExecuteScript returns failure, and signal or propagate the exception, as
|
|
|
|
* appropriate.
|
|
|
|
*/
|
2000-01-18 11:06:05 +00:00
|
|
|
#define JSREPORT_IS_WARNING(flags) (((flags) & JSREPORT_WARNING) != 0)
|
|
|
|
#define JSREPORT_IS_EXCEPTION(flags) (((flags) & JSREPORT_EXCEPTION) != 0)
|
|
|
|
#define JSREPORT_IS_STRICT(flags) (((flags) & JSREPORT_STRICT) != 0)
|
2009-11-19 17:23:20 +00:00
|
|
|
#define JSREPORT_IS_STRICT_MODE_ERROR(flags) (((flags) & \
|
|
|
|
JSREPORT_STRICT_MODE_ERROR) != 0)
|
2012-01-15 08:13:09 +00:00
|
|
|
extern JS_PUBLIC_API(JSErrorReporter)
|
2014-09-09 23:02:10 +00:00
|
|
|
JS_GetErrorReporter(JSRuntime *rt);
|
1998-10-14 10:22:38 +00:00
|
|
|
|
1998-04-24 00:31:11 +00:00
|
|
|
extern JS_PUBLIC_API(JSErrorReporter)
|
2014-09-09 23:02:10 +00:00
|
|
|
JS_SetErrorReporter(JSRuntime *rt, JSErrorReporter er);
|
1998-03-28 02:44:41 +00:00
|
|
|
|
2014-01-28 17:19:48 +00:00
|
|
|
namespace JS {
|
|
|
|
|
|
|
|
extern JS_PUBLIC_API(bool)
|
2014-07-03 00:48:35 +00:00
|
|
|
CreateError(JSContext *cx, JSExnType type, HandleString stack,
|
|
|
|
HandleString fileName, uint32_t lineNumber, uint32_t columnNumber,
|
|
|
|
JSErrorReport *report, HandleString message, MutableHandleValue rval);
|
2014-01-28 17:19:48 +00:00
|
|
|
|
1998-03-28 02:44:41 +00:00
|
|
|
/************************************************************************/
|
|
|
|
|
2014-04-11 14:59:46 +00:00
|
|
|
/*
|
|
|
|
* Weak Maps.
|
|
|
|
*/
|
|
|
|
|
|
|
|
extern JS_PUBLIC_API(JSObject *)
|
|
|
|
NewWeakMapObject(JSContext *cx);
|
|
|
|
|
|
|
|
extern JS_PUBLIC_API(bool)
|
|
|
|
IsWeakMapObject(JSObject *obj);
|
|
|
|
|
|
|
|
extern JS_PUBLIC_API(bool)
|
|
|
|
GetWeakMapEntry(JSContext *cx, JS::HandleObject mapObj, JS::HandleObject key,
|
|
|
|
JS::MutableHandleValue val);
|
|
|
|
|
|
|
|
extern JS_PUBLIC_API(bool)
|
|
|
|
SetWeakMapEntry(JSContext *cx, JS::HandleObject mapObj, JS::HandleObject key,
|
|
|
|
JS::HandleValue val);
|
|
|
|
|
2015-01-31 00:22:48 +00:00
|
|
|
/*
|
|
|
|
* Map
|
|
|
|
*/
|
|
|
|
extern JS_PUBLIC_API(JSObject *)
|
|
|
|
NewMapObject(JSContext *cx);
|
|
|
|
|
|
|
|
extern JS_PUBLIC_API(uint32_t)
|
|
|
|
MapSize(JSContext *cx, HandleObject obj);
|
|
|
|
|
|
|
|
extern JS_PUBLIC_API(bool)
|
|
|
|
MapGet(JSContext *cx, HandleObject obj,
|
|
|
|
HandleValue key, MutableHandleValue rval);
|
|
|
|
|
|
|
|
extern JS_PUBLIC_API(bool)
|
|
|
|
MapHas(JSContext *cx, HandleObject obj, HandleValue key, bool *rval);
|
|
|
|
|
|
|
|
extern JS_PUBLIC_API(bool)
|
|
|
|
MapSet(JSContext *cx, HandleObject obj, HandleValue key, HandleValue val);
|
|
|
|
|
|
|
|
extern JS_PUBLIC_API(bool)
|
|
|
|
MapClear(JSContext *cx, HandleObject obj);
|
|
|
|
|
|
|
|
extern JS_PUBLIC_API(bool)
|
|
|
|
MapKeys(JSContext *cx, HandleObject obj, MutableHandleValue rval);
|
|
|
|
|
|
|
|
extern JS_PUBLIC_API(bool)
|
|
|
|
MapValues(JSContext *cx, HandleObject obj, MutableHandleValue rval);
|
|
|
|
|
|
|
|
extern JS_PUBLIC_API(bool)
|
|
|
|
MapEntries(JSContext *cx, HandleObject obj, MutableHandleValue rval);
|
|
|
|
|
2014-04-11 14:59:46 +00:00
|
|
|
} /* namespace JS */
|
|
|
|
|
2011-01-18 22:11:03 +00:00
|
|
|
/*
|
|
|
|
* Dates.
|
|
|
|
*/
|
|
|
|
|
|
|
|
extern JS_PUBLIC_API(JSObject *)
|
|
|
|
JS_NewDateObject(JSContext *cx, int year, int mon, int mday, int hour, int min, int sec);
|
|
|
|
|
|
|
|
extern JS_PUBLIC_API(JSObject *)
|
2012-02-24 22:19:52 +00:00
|
|
|
JS_NewDateObjectMsec(JSContext *cx, double msec);
|
2011-01-18 22:11:03 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Infallible predicate to test whether obj is a date object.
|
|
|
|
*/
|
2013-08-08 22:53:04 +00:00
|
|
|
extern JS_PUBLIC_API(bool)
|
2013-09-19 07:54:01 +00:00
|
|
|
JS_ObjectIsDate(JSContext *cx, JS::HandleObject obj);
|
2011-01-18 22:11:03 +00:00
|
|
|
|
2012-07-13 22:56:08 +00:00
|
|
|
/*
|
|
|
|
* Clears the cache of calculated local time from each Date object.
|
|
|
|
* Call to propagate a system timezone change.
|
|
|
|
*/
|
|
|
|
extern JS_PUBLIC_API(void)
|
|
|
|
JS_ClearDateCaches(JSContext *cx);
|
|
|
|
|
2011-01-18 22:11:03 +00:00
|
|
|
/************************************************************************/
|
|
|
|
|
1998-03-28 02:44:41 +00:00
|
|
|
/*
|
|
|
|
* Regular Expressions.
|
|
|
|
*/
|
2014-06-26 01:47:04 +00:00
|
|
|
#define JSREG_FOLD 0x01u /* fold uppercase to lowercase */
|
|
|
|
#define JSREG_GLOB 0x02u /* global exec, creates array of matches */
|
|
|
|
#define JSREG_MULTILINE 0x04u /* treat ^ and $ as begin and end of line */
|
|
|
|
#define JSREG_STICKY 0x08u /* only match starting at lastIndex */
|
1998-03-28 02:44:41 +00:00
|
|
|
|
1998-04-24 00:31:11 +00:00
|
|
|
extern JS_PUBLIC_API(JSObject *)
|
2014-10-01 15:22:14 +00:00
|
|
|
JS_NewRegExpObject(JSContext *cx, JS::HandleObject obj, const char *bytes, size_t length,
|
2013-09-19 07:54:01 +00:00
|
|
|
unsigned flags);
|
1998-03-28 02:44:41 +00:00
|
|
|
|
1998-04-24 00:31:11 +00:00
|
|
|
extern JS_PUBLIC_API(JSObject *)
|
2014-10-01 15:22:14 +00:00
|
|
|
JS_NewUCRegExpObject(JSContext *cx, JS::HandleObject obj, const char16_t *chars, size_t length,
|
2013-09-19 07:54:01 +00:00
|
|
|
unsigned flags);
|
1998-03-28 02:44:41 +00:00
|
|
|
|
2014-04-23 03:13:24 +00:00
|
|
|
extern JS_PUBLIC_API(bool)
|
2013-09-19 07:54:01 +00:00
|
|
|
JS_SetRegExpInput(JSContext *cx, JS::HandleObject obj, JS::HandleString input,
|
|
|
|
bool multiline);
|
1998-03-28 02:44:41 +00:00
|
|
|
|
2014-04-23 03:13:24 +00:00
|
|
|
extern JS_PUBLIC_API(bool)
|
2013-09-19 07:54:01 +00:00
|
|
|
JS_ClearRegExpStatics(JSContext *cx, JS::HandleObject obj);
|
1998-03-28 02:44:41 +00:00
|
|
|
|
2013-08-08 22:53:04 +00:00
|
|
|
extern JS_PUBLIC_API(bool)
|
2013-09-19 07:54:01 +00:00
|
|
|
JS_ExecuteRegExp(JSContext *cx, JS::HandleObject obj, JS::HandleObject reobj,
|
2014-07-22 04:43:21 +00:00
|
|
|
char16_t *chars, size_t length, size_t *indexp, bool test,
|
2013-09-19 07:54:01 +00:00
|
|
|
JS::MutableHandleValue rval);
|
2010-08-18 19:26:22 +00:00
|
|
|
|
2010-09-13 22:53:50 +00:00
|
|
|
/* RegExp interface for clients without a global object. */
|
|
|
|
|
|
|
|
extern JS_PUBLIC_API(JSObject *)
|
2012-02-28 23:11:11 +00:00
|
|
|
JS_NewRegExpObjectNoStatics(JSContext *cx, char *bytes, size_t length, unsigned flags);
|
2010-09-13 22:53:50 +00:00
|
|
|
|
|
|
|
extern JS_PUBLIC_API(JSObject *)
|
2014-07-22 04:43:21 +00:00
|
|
|
JS_NewUCRegExpObjectNoStatics(JSContext *cx, char16_t *chars, size_t length, unsigned flags);
|
2010-09-13 22:53:50 +00:00
|
|
|
|
2013-08-08 22:53:04 +00:00
|
|
|
extern JS_PUBLIC_API(bool)
|
2014-07-22 04:43:21 +00:00
|
|
|
JS_ExecuteRegExpNoStatics(JSContext *cx, JS::HandleObject reobj, char16_t *chars, size_t length,
|
2013-09-19 07:54:01 +00:00
|
|
|
size_t *indexp, bool test, JS::MutableHandleValue rval);
|
1998-03-28 02:44:41 +00:00
|
|
|
|
2013-08-08 22:53:04 +00:00
|
|
|
extern JS_PUBLIC_API(bool)
|
2013-09-19 07:54:01 +00:00
|
|
|
JS_ObjectIsRegExp(JSContext *cx, JS::HandleObject obj);
|
2011-05-18 03:04:28 +00:00
|
|
|
|
2012-02-28 23:11:11 +00:00
|
|
|
extern JS_PUBLIC_API(unsigned)
|
2013-09-19 07:54:01 +00:00
|
|
|
JS_GetRegExpFlags(JSContext *cx, JS::HandleObject obj);
|
2011-05-09 03:10:21 +00:00
|
|
|
|
|
|
|
extern JS_PUBLIC_API(JSString *)
|
2013-09-19 07:54:01 +00:00
|
|
|
JS_GetRegExpSource(JSContext *cx, JS::HandleObject obj);
|
2011-05-09 03:10:21 +00:00
|
|
|
|
1998-03-28 02:44:41 +00:00
|
|
|
/************************************************************************/
|
|
|
|
|
2013-08-08 22:53:04 +00:00
|
|
|
extern JS_PUBLIC_API(bool)
|
1998-04-24 00:31:11 +00:00
|
|
|
JS_IsExceptionPending(JSContext *cx);
|
|
|
|
|
2013-08-08 22:53:04 +00:00
|
|
|
extern JS_PUBLIC_API(bool)
|
2013-09-19 07:54:01 +00:00
|
|
|
JS_GetPendingException(JSContext *cx, JS::MutableHandleValue vp);
|
1998-04-24 00:31:11 +00:00
|
|
|
|
|
|
|
extern JS_PUBLIC_API(void)
|
2013-09-19 07:54:01 +00:00
|
|
|
JS_SetPendingException(JSContext *cx, JS::HandleValue v);
|
1998-04-24 00:31:11 +00:00
|
|
|
|
|
|
|
extern JS_PUBLIC_API(void)
|
|
|
|
JS_ClearPendingException(JSContext *cx);
|
2004-07-17 02:39:55 +00:00
|
|
|
|
2013-08-08 22:53:04 +00:00
|
|
|
extern JS_PUBLIC_API(bool)
|
2004-07-17 02:39:55 +00:00
|
|
|
JS_ReportPendingException(JSContext *cx);
|
1998-04-24 00:31:11 +00:00
|
|
|
|
2014-02-26 14:55:34 +00:00
|
|
|
namespace JS {
|
|
|
|
|
1999-06-08 02:15:57 +00:00
|
|
|
/*
|
2014-02-26 14:55:34 +00:00
|
|
|
* Save and later restore the current exception state of a given JSContext.
|
|
|
|
* This is useful for implementing behavior in C++ that's like try/catch
|
|
|
|
* or try/finally in JS.
|
|
|
|
*
|
|
|
|
* Typical usage:
|
1999-06-08 02:15:57 +00:00
|
|
|
*
|
2014-11-19 04:27:16 +00:00
|
|
|
* bool ok = JS::Evaluate(cx, ...);
|
2014-02-26 14:55:34 +00:00
|
|
|
* AutoSaveExceptionState savedExc(cx);
|
|
|
|
* ... cleanup that might re-enter JS ...
|
|
|
|
* return ok;
|
1999-06-08 02:15:57 +00:00
|
|
|
*/
|
2014-02-26 14:55:34 +00:00
|
|
|
class JS_PUBLIC_API(AutoSaveExceptionState)
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
JSContext *context;
|
2014-06-05 22:10:33 +00:00
|
|
|
bool wasPropagatingForcedReturn;
|
2014-11-19 00:42:02 +00:00
|
|
|
bool wasOverRecursed;
|
2014-02-26 14:55:34 +00:00
|
|
|
bool wasThrowing;
|
|
|
|
RootedValue exceptionValue;
|
|
|
|
|
|
|
|
public:
|
|
|
|
/*
|
|
|
|
* Take a snapshot of cx's current exception state. Then clear any current
|
|
|
|
* pending exception in cx.
|
|
|
|
*/
|
|
|
|
explicit AutoSaveExceptionState(JSContext *cx);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If neither drop() nor restore() was called, restore the exception
|
|
|
|
* state only if no exception is currently pending on cx.
|
|
|
|
*/
|
|
|
|
~AutoSaveExceptionState();
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Discard any stored exception state.
|
|
|
|
* If this is called, the destructor is a no-op.
|
|
|
|
*/
|
|
|
|
void drop() {
|
2014-06-05 22:10:33 +00:00
|
|
|
wasPropagatingForcedReturn = false;
|
2014-11-19 00:42:02 +00:00
|
|
|
wasOverRecursed = false;
|
2014-02-26 14:55:34 +00:00
|
|
|
wasThrowing = false;
|
|
|
|
exceptionValue.setUndefined();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Replace cx's exception state with the stored exception state. Then
|
|
|
|
* discard the stored exception state. If this is called, the
|
|
|
|
* destructor is a no-op.
|
|
|
|
*/
|
|
|
|
void restore();
|
|
|
|
};
|
|
|
|
|
|
|
|
} /* namespace JS */
|
|
|
|
|
|
|
|
/* Deprecated API. Use AutoSaveExceptionState instead. */
|
1998-11-05 00:08:43 +00:00
|
|
|
extern JS_PUBLIC_API(JSExceptionState *)
|
|
|
|
JS_SaveExceptionState(JSContext *cx);
|
|
|
|
|
|
|
|
extern JS_PUBLIC_API(void)
|
|
|
|
JS_RestoreExceptionState(JSContext *cx, JSExceptionState *state);
|
|
|
|
|
|
|
|
extern JS_PUBLIC_API(void)
|
|
|
|
JS_DropExceptionState(JSContext *cx, JSExceptionState *state);
|
|
|
|
|
1999-10-05 21:07:23 +00:00
|
|
|
/*
|
2014-01-30 17:30:29 +00:00
|
|
|
* If the given object is an exception object, the exception will have (or be
|
|
|
|
* able to lazily create) an error report struct, and this function will return
|
|
|
|
* the address of that struct. Otherwise, it returns nullptr. The lifetime
|
2013-10-07 16:42:55 +00:00
|
|
|
* of the error report struct that might be returned is the same as the
|
|
|
|
* lifetime of the exception object.
|
1999-10-05 21:07:23 +00:00
|
|
|
*/
|
|
|
|
extern JS_PUBLIC_API(JSErrorReport *)
|
2014-01-30 17:30:29 +00:00
|
|
|
JS_ErrorFromException(JSContext *cx, JS::HandleObject obj);
|
1999-10-05 21:07:23 +00:00
|
|
|
|
2007-10-01 00:31:22 +00:00
|
|
|
/*
|
|
|
|
* Throws a StopIteration exception on cx.
|
|
|
|
*/
|
2013-08-08 22:53:04 +00:00
|
|
|
extern JS_PUBLIC_API(bool)
|
2007-10-01 00:31:22 +00:00
|
|
|
JS_ThrowStopIteration(JSContext *cx);
|
|
|
|
|
2013-09-30 19:20:51 +00:00
|
|
|
extern JS_PUBLIC_API(bool)
|
|
|
|
JS_IsStopIteration(jsval v);
|
|
|
|
|
2012-01-11 08:23:07 +00:00
|
|
|
extern JS_PUBLIC_API(intptr_t)
|
|
|
|
JS_GetCurrentThread();
|
|
|
|
|
2011-07-01 21:11:31 +00:00
|
|
|
/*
|
|
|
|
* A JS runtime always has an "owner thread". The owner thread is set when the
|
|
|
|
* runtime is created (to the current thread) and practically all entry points
|
|
|
|
* into the JS engine check that a runtime (or anything contained in the
|
|
|
|
* runtime: context, compartment, object, etc) is only touched by its owner
|
|
|
|
* thread. Embeddings may check this invariant outside the JS engine by calling
|
|
|
|
* JS_AbortIfWrongThread (which will abort if not on the owner thread, even for
|
|
|
|
* non-debug builds).
|
|
|
|
*/
|
|
|
|
|
|
|
|
extern JS_PUBLIC_API(void)
|
|
|
|
JS_AbortIfWrongThread(JSRuntime *rt);
|
|
|
|
|
1998-04-24 00:31:11 +00:00
|
|
|
/************************************************************************/
|
|
|
|
|
2010-08-16 19:35:04 +00:00
|
|
|
/*
|
2012-03-12 23:16:40 +00:00
|
|
|
* A constructor can request that the JS engine create a default new 'this'
|
|
|
|
* object of the given class, using the callee to determine parentage and
|
|
|
|
* [[Prototype]].
|
2010-08-16 19:35:04 +00:00
|
|
|
*/
|
|
|
|
extern JS_PUBLIC_API(JSObject *)
|
2014-03-20 09:32:37 +00:00
|
|
|
JS_NewObjectForConstructor(JSContext *cx, const JSClass *clasp, const JS::CallArgs& args);
|
2010-08-16 19:35:04 +00:00
|
|
|
|
|
|
|
/************************************************************************/
|
|
|
|
|
2007-05-15 23:27:20 +00:00
|
|
|
#ifdef JS_GC_ZEAL
|
2011-06-02 00:48:52 +00:00
|
|
|
#define JS_DEFAULT_ZEAL_FREQ 100
|
|
|
|
|
2015-01-03 18:12:28 +00:00
|
|
|
extern JS_PUBLIC_API(void)
|
2015-01-09 06:41:31 +00:00
|
|
|
JS_GetGCZeal(JSContext *cx, uint8_t *zeal, uint32_t *frequency, uint32_t *nextScheduled);
|
2015-01-03 18:12:28 +00:00
|
|
|
|
2011-06-02 00:48:52 +00:00
|
|
|
extern JS_PUBLIC_API(void)
|
2012-04-03 18:41:56 +00:00
|
|
|
JS_SetGCZeal(JSContext *cx, uint8_t zeal, uint32_t frequency);
|
2011-06-02 00:48:52 +00:00
|
|
|
|
2007-05-15 23:27:20 +00:00
|
|
|
extern JS_PUBLIC_API(void)
|
2012-04-03 18:41:56 +00:00
|
|
|
JS_ScheduleGC(JSContext *cx, uint32_t count);
|
2007-05-15 23:27:20 +00:00
|
|
|
#endif
|
|
|
|
|
2012-11-26 21:30:37 +00:00
|
|
|
extern JS_PUBLIC_API(void)
|
2014-02-26 09:25:36 +00:00
|
|
|
JS_SetParallelParsingEnabled(JSRuntime *rt, bool enabled);
|
2013-08-22 13:22:33 +00:00
|
|
|
|
|
|
|
extern JS_PUBLIC_API(void)
|
2014-06-16 10:05:12 +00:00
|
|
|
JS_SetOffthreadIonCompilationEnabled(JSRuntime *rt, bool enabled);
|
2012-11-26 21:30:37 +00:00
|
|
|
|
2015-02-12 10:50:51 +00:00
|
|
|
#define JIT_COMPILER_OPTIONS(Register) \
|
|
|
|
Register(BASELINE_WARMUP_TRIGGER, "baseline.warmup.trigger") \
|
|
|
|
Register(ION_WARMUP_TRIGGER, "ion.warmup.trigger") \
|
|
|
|
Register(ION_GVN_ENABLE, "ion.gvn.enable") \
|
|
|
|
Register(ION_ENABLE, "ion.enable") \
|
|
|
|
Register(BASELINE_ENABLE, "baseline.enable") \
|
2014-07-18 10:14:51 +00:00
|
|
|
Register(OFFTHREAD_COMPILATION_ENABLE, "offthread-compilation.enable") \
|
|
|
|
Register(SIGNALS_ENABLE, "signals.enable")
|
2013-08-27 20:45:14 +00:00
|
|
|
|
|
|
|
typedef enum JSJitCompilerOption {
|
|
|
|
#define JIT_COMPILER_DECLARE(key, str) \
|
|
|
|
JSJITCOMPILER_ ## key,
|
|
|
|
|
|
|
|
JIT_COMPILER_OPTIONS(JIT_COMPILER_DECLARE)
|
|
|
|
#undef JIT_COMPILER_DECLARE
|
|
|
|
|
|
|
|
JSJITCOMPILER_NOT_AN_OPTION
|
|
|
|
} JSJitCompilerOption;
|
2013-06-24 12:10:55 +00:00
|
|
|
|
|
|
|
extern JS_PUBLIC_API(void)
|
2014-02-26 09:25:36 +00:00
|
|
|
JS_SetGlobalJitCompilerOption(JSRuntime *rt, JSJitCompilerOption opt, uint32_t value);
|
2014-01-06 15:03:41 +00:00
|
|
|
extern JS_PUBLIC_API(int)
|
2014-02-26 09:25:36 +00:00
|
|
|
JS_GetGlobalJitCompilerOption(JSRuntime *rt, JSJitCompilerOption opt);
|
2013-06-24 12:10:55 +00:00
|
|
|
|
2011-11-04 16:19:07 +00:00
|
|
|
/*
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-09 03:54:10 +00:00
|
|
|
* Convert a uint32_t index into a jsid.
|
2011-11-04 16:19:07 +00:00
|
|
|
*/
|
2013-08-08 22:53:04 +00:00
|
|
|
extern JS_PUBLIC_API(bool)
|
2013-09-19 07:54:02 +00:00
|
|
|
JS_IndexToId(JSContext *cx, uint32_t index, JS::MutableHandleId);
|
2011-11-04 16:19:07 +00:00
|
|
|
|
2013-01-28 13:46:10 +00:00
|
|
|
/*
|
|
|
|
* Convert chars into a jsid.
|
|
|
|
*
|
|
|
|
* |chars| may not be an index.
|
|
|
|
*/
|
2013-08-08 22:53:04 +00:00
|
|
|
extern JS_PUBLIC_API(bool)
|
2013-09-19 07:54:02 +00:00
|
|
|
JS_CharsToId(JSContext* cx, JS::TwoByteChars chars, JS::MutableHandleId);
|
2013-01-28 13:46:10 +00:00
|
|
|
|
2011-11-21 14:56:24 +00:00
|
|
|
/*
|
|
|
|
* Test if the given string is a valid ECMAScript identifier
|
|
|
|
*/
|
2013-08-08 22:53:04 +00:00
|
|
|
extern JS_PUBLIC_API(bool)
|
2013-09-19 07:54:02 +00:00
|
|
|
JS_IsIdentifier(JSContext *cx, JS::HandleString str, bool *isIdentifier);
|
2011-11-21 14:56:24 +00:00
|
|
|
|
2014-12-11 18:07:44 +00:00
|
|
|
/*
|
|
|
|
* Test whether the given chars + length are a valid ECMAScript identifier.
|
|
|
|
* This version is infallible, so just returns whether the chars are an
|
|
|
|
* identifier.
|
|
|
|
*/
|
|
|
|
extern JS_PUBLIC_API(bool)
|
|
|
|
JS_IsIdentifier(const char16_t *chars, size_t length);
|
|
|
|
|
2014-02-25 15:43:14 +00:00
|
|
|
namespace JS {
|
|
|
|
|
|
|
|
/*
|
|
|
|
* AutoFilename encapsulates a pointer to a C-string and keeps the C-string
|
|
|
|
* alive for as long as the associated AutoFilename object is alive.
|
|
|
|
*/
|
|
|
|
class MOZ_STACK_CLASS JS_PUBLIC_API(AutoFilename)
|
|
|
|
{
|
|
|
|
void *scriptSource_;
|
|
|
|
|
2015-01-06 23:35:02 +00:00
|
|
|
AutoFilename(const AutoFilename &) = delete;
|
|
|
|
void operator=(const AutoFilename &) = delete;
|
2014-02-25 15:43:14 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
AutoFilename() : scriptSource_(nullptr) {}
|
|
|
|
~AutoFilename() { reset(nullptr); }
|
|
|
|
|
|
|
|
const char *get() const;
|
|
|
|
|
|
|
|
void reset(void *newScriptSource);
|
|
|
|
};
|
|
|
|
|
2012-03-06 23:33:12 +00:00
|
|
|
/*
|
2014-02-25 15:43:14 +00:00
|
|
|
* Return the current filename and line number of the most currently running
|
2012-03-06 23:33:12 +00:00
|
|
|
* frame. Returns true if a scripted frame was found, false otherwise.
|
2013-12-12 01:51:57 +00:00
|
|
|
*
|
|
|
|
* If a the embedding has hidden the scripted caller for the topmost activation
|
|
|
|
* record, this will also return false.
|
2012-03-06 23:33:12 +00:00
|
|
|
*/
|
2013-08-08 22:53:04 +00:00
|
|
|
extern JS_PUBLIC_API(bool)
|
2014-02-25 15:43:14 +00:00
|
|
|
DescribeScriptedCaller(JSContext *cx, AutoFilename *filename = nullptr,
|
|
|
|
unsigned *lineno = nullptr);
|
2012-03-06 23:33:12 +00:00
|
|
|
|
2014-02-25 15:43:14 +00:00
|
|
|
extern JS_PUBLIC_API(JSObject *)
|
|
|
|
GetScriptedCallerGlobal(JSContext *cx);
|
2013-12-12 01:51:57 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Informs the JS engine that the scripted caller should be hidden. This can be
|
|
|
|
* used by the embedding to maintain an override of the scripted caller in its
|
|
|
|
* calculations, by hiding the scripted caller in the JS engine and pushing data
|
2014-02-27 16:47:54 +00:00
|
|
|
* onto a separate stack, which it inspects when DescribeScriptedCaller returns
|
|
|
|
* null.
|
2013-12-12 01:51:57 +00:00
|
|
|
*
|
|
|
|
* We maintain a counter on each activation record. Add() increments the counter
|
|
|
|
* of the topmost activation, and Remove() decrements it. The count may never
|
|
|
|
* drop below zero, and must always be exactly zero when the activation is
|
|
|
|
* popped from the stack.
|
|
|
|
*/
|
|
|
|
extern JS_PUBLIC_API(void)
|
|
|
|
HideScriptedCaller(JSContext *cx);
|
|
|
|
|
|
|
|
extern JS_PUBLIC_API(void)
|
|
|
|
UnhideScriptedCaller(JSContext *cx);
|
|
|
|
|
|
|
|
class AutoHideScriptedCaller
|
|
|
|
{
|
|
|
|
public:
|
2014-05-26 01:46:24 +00:00
|
|
|
explicit AutoHideScriptedCaller(JSContext *cx
|
|
|
|
MOZ_GUARD_OBJECT_NOTIFIER_PARAM)
|
2013-12-12 01:51:57 +00:00
|
|
|
: mContext(cx)
|
|
|
|
{
|
|
|
|
MOZ_GUARD_OBJECT_NOTIFIER_INIT;
|
|
|
|
HideScriptedCaller(mContext);
|
|
|
|
}
|
|
|
|
~AutoHideScriptedCaller() {
|
|
|
|
UnhideScriptedCaller(mContext);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
JSContext *mContext;
|
|
|
|
MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER
|
|
|
|
};
|
|
|
|
|
2014-01-28 17:19:48 +00:00
|
|
|
} /* namespace JS */
|
2012-03-06 23:33:12 +00:00
|
|
|
|
2012-02-20 10:58:00 +00:00
|
|
|
/*
|
|
|
|
* Encode/Decode interpreted scripts and functions to/from memory.
|
|
|
|
*/
|
|
|
|
|
|
|
|
extern JS_PUBLIC_API(void *)
|
2013-09-20 09:22:59 +00:00
|
|
|
JS_EncodeScript(JSContext *cx, JS::HandleScript script, uint32_t *lengthp);
|
2012-02-20 10:58:00 +00:00
|
|
|
|
|
|
|
extern JS_PUBLIC_API(void *)
|
2013-09-20 09:22:59 +00:00
|
|
|
JS_EncodeInterpretedFunction(JSContext *cx, JS::HandleObject funobj, uint32_t *lengthp);
|
2012-02-20 10:58:00 +00:00
|
|
|
|
|
|
|
extern JS_PUBLIC_API(JSScript *)
|
2014-09-29 08:44:30 +00:00
|
|
|
JS_DecodeScript(JSContext *cx, const void *data, uint32_t length);
|
2012-02-20 10:58:00 +00:00
|
|
|
|
|
|
|
extern JS_PUBLIC_API(JSObject *)
|
2014-09-29 08:44:30 +00:00
|
|
|
JS_DecodeInterpretedFunction(JSContext *cx, const void *data, uint32_t length);
|
2012-02-20 10:58:00 +00:00
|
|
|
|
2013-10-15 17:13:34 +00:00
|
|
|
namespace JS {
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This callback represents a request by the JS engine to open for reading the
|
2013-11-18 22:02:05 +00:00
|
|
|
* existing cache entry for the given global and char range that may contain a
|
|
|
|
* module. If a cache entry exists, the callback shall return 'true' and return
|
|
|
|
* the size, base address and an opaque file handle as outparams. If the
|
|
|
|
* callback returns 'true', the JS engine guarantees a call to
|
|
|
|
* CloseAsmJSCacheEntryForReadOp, passing the same base address, size and
|
|
|
|
* handle.
|
2013-10-15 17:13:34 +00:00
|
|
|
*/
|
|
|
|
typedef bool
|
2014-07-22 04:43:21 +00:00
|
|
|
(* OpenAsmJSCacheEntryForReadOp)(HandleObject global, const char16_t *begin, const char16_t *limit,
|
2013-11-18 22:02:05 +00:00
|
|
|
size_t *size, const uint8_t **memory, intptr_t *handle);
|
2013-10-15 17:13:34 +00:00
|
|
|
typedef void
|
2014-05-06 17:58:00 +00:00
|
|
|
(* CloseAsmJSCacheEntryForReadOp)(size_t size, const uint8_t *memory, intptr_t handle);
|
2013-10-15 17:13:34 +00:00
|
|
|
|
2014-10-22 22:28:07 +00:00
|
|
|
/* The list of reasons why an asm.js module may not be stored in the cache. */
|
|
|
|
enum AsmJSCacheResult
|
|
|
|
{
|
|
|
|
AsmJSCache_MIN,
|
|
|
|
AsmJSCache_Success = AsmJSCache_MIN,
|
|
|
|
AsmJSCache_ModuleTooSmall,
|
|
|
|
AsmJSCache_SynchronousScript,
|
|
|
|
AsmJSCache_QuotaExceeded,
|
|
|
|
AsmJSCache_Disabled_Internal,
|
|
|
|
AsmJSCache_Disabled_ShellFlags,
|
|
|
|
AsmJSCache_Disabled_JitInspector,
|
|
|
|
AsmJSCache_InternalError,
|
|
|
|
AsmJSCache_LIMIT
|
|
|
|
};
|
|
|
|
|
2013-10-15 17:13:34 +00:00
|
|
|
/*
|
|
|
|
* This callback represents a request by the JS engine to open for writing a
|
2013-11-18 22:02:05 +00:00
|
|
|
* cache entry of the given size for the given global and char range containing
|
|
|
|
* the just-compiled module. If cache entry space is available, the callback
|
|
|
|
* shall return 'true' and return the base address and an opaque file handle as
|
|
|
|
* outparams. If the callback returns 'true', the JS engine guarantees a call
|
|
|
|
* to CloseAsmJSCacheEntryForWriteOp passing the same base address, size and
|
|
|
|
* handle.
|
2014-03-05 20:47:10 +00:00
|
|
|
*
|
|
|
|
* If 'installed' is true, then the cache entry is associated with a permanently
|
|
|
|
* installed JS file (e.g., in a packaged webapp). This information allows the
|
|
|
|
* embedding to store the cache entry in a installed location associated with
|
|
|
|
* the principal of 'global' where it will not be evicted until the associated
|
|
|
|
* installed JS file is removed.
|
2013-10-15 17:13:34 +00:00
|
|
|
*/
|
2014-10-22 22:28:07 +00:00
|
|
|
typedef AsmJSCacheResult
|
2014-03-05 20:47:10 +00:00
|
|
|
(* OpenAsmJSCacheEntryForWriteOp)(HandleObject global, bool installed,
|
2014-07-22 04:43:21 +00:00
|
|
|
const char16_t *begin, const char16_t *end,
|
2013-11-18 22:02:05 +00:00
|
|
|
size_t size, uint8_t **memory, intptr_t *handle);
|
2013-10-15 17:13:34 +00:00
|
|
|
typedef void
|
2014-05-06 17:58:00 +00:00
|
|
|
(* CloseAsmJSCacheEntryForWriteOp)(size_t size, uint8_t *memory, intptr_t handle);
|
2013-10-15 17:13:34 +00:00
|
|
|
|
2013-12-05 04:32:52 +00:00
|
|
|
typedef js::Vector<char, 0, js::SystemAllocPolicy> BuildIdCharVector;
|
|
|
|
|
2013-10-15 17:13:34 +00:00
|
|
|
// Return the buildId (represented as a sequence of characters) associated with
|
|
|
|
// the currently-executing build. If the JS engine is embedded such that a
|
|
|
|
// single cache entry can be observed by different compiled versions of the JS
|
|
|
|
// engine, it is critical that the buildId shall change for each new build of
|
|
|
|
// the JS engine.
|
2013-12-05 04:32:52 +00:00
|
|
|
|
2013-10-15 17:13:34 +00:00
|
|
|
typedef bool
|
2013-12-05 04:32:52 +00:00
|
|
|
(* BuildIdOp)(BuildIdCharVector *buildId);
|
2013-10-15 17:13:34 +00:00
|
|
|
|
|
|
|
struct AsmJSCacheOps
|
|
|
|
{
|
|
|
|
OpenAsmJSCacheEntryForReadOp openEntryForRead;
|
|
|
|
CloseAsmJSCacheEntryForReadOp closeEntryForRead;
|
|
|
|
OpenAsmJSCacheEntryForWriteOp openEntryForWrite;
|
|
|
|
CloseAsmJSCacheEntryForWriteOp closeEntryForWrite;
|
|
|
|
BuildIdOp buildId;
|
|
|
|
};
|
|
|
|
|
|
|
|
extern JS_PUBLIC_API(void)
|
|
|
|
SetAsmJSCacheOps(JSRuntime *rt, const AsmJSCacheOps *callbacks);
|
|
|
|
|
2014-01-29 00:16:03 +00:00
|
|
|
/*
|
|
|
|
* Convenience class for imitating a JS level for-of loop. Typical usage:
|
|
|
|
*
|
|
|
|
* ForOfIterator it(cx);
|
|
|
|
* if (!it.init(iterable))
|
|
|
|
* return false;
|
|
|
|
* RootedValue val(cx);
|
|
|
|
* while (true) {
|
|
|
|
* bool done;
|
|
|
|
* if (!it.next(&val, &done))
|
|
|
|
* return false;
|
|
|
|
* if (done)
|
|
|
|
* break;
|
|
|
|
* if (!DoStuff(cx, val))
|
|
|
|
* return false;
|
|
|
|
* }
|
|
|
|
*/
|
|
|
|
class MOZ_STACK_CLASS JS_PUBLIC_API(ForOfIterator) {
|
|
|
|
protected:
|
|
|
|
JSContext *cx_;
|
2014-02-13 19:29:00 +00:00
|
|
|
/*
|
|
|
|
* Use the ForOfPIC on the global object (see vm/GlobalObject.h) to try
|
|
|
|
* to optimize iteration across arrays.
|
|
|
|
*
|
|
|
|
* Case 1: Regular Iteration
|
|
|
|
* iterator - pointer to the iterator object.
|
|
|
|
* index - fixed to NOT_ARRAY (== UINT32_MAX)
|
|
|
|
*
|
|
|
|
* Case 2: Optimized Array Iteration
|
|
|
|
* iterator - pointer to the array object.
|
|
|
|
* index - current position in array.
|
|
|
|
*
|
|
|
|
* The cases are distinguished by whether or not |index| is equal to NOT_ARRAY.
|
|
|
|
*/
|
2014-01-29 00:16:03 +00:00
|
|
|
JS::RootedObject iterator;
|
2014-02-13 19:29:00 +00:00
|
|
|
uint32_t index;
|
|
|
|
|
|
|
|
static const uint32_t NOT_ARRAY = UINT32_MAX;
|
2014-01-29 00:16:03 +00:00
|
|
|
|
2015-01-06 23:35:02 +00:00
|
|
|
ForOfIterator(const ForOfIterator &) = delete;
|
|
|
|
ForOfIterator &operator=(const ForOfIterator &) = delete;
|
2014-01-29 00:16:03 +00:00
|
|
|
|
|
|
|
public:
|
2014-05-26 01:46:24 +00:00
|
|
|
explicit ForOfIterator(JSContext *cx) : cx_(cx), iterator(cx_), index(NOT_ARRAY) { }
|
2014-01-29 00:16:03 +00:00
|
|
|
|
|
|
|
enum NonIterableBehavior {
|
|
|
|
ThrowOnNonIterable,
|
|
|
|
AllowNonIterable
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
2014-10-01 01:26:28 +00:00
|
|
|
* Initialize the iterator. If AllowNonIterable is passed then if getting
|
|
|
|
* the @@iterator property from iterable returns undefined init() will just
|
|
|
|
* return true instead of throwing. Callers must then check
|
|
|
|
* valueIsIterable() before continuing with the iteration.
|
2014-01-29 00:16:03 +00:00
|
|
|
*/
|
2014-01-29 01:54:31 +00:00
|
|
|
bool init(JS::HandleValue iterable,
|
|
|
|
NonIterableBehavior nonIterableBehavior = ThrowOnNonIterable);
|
2014-01-29 00:16:03 +00:00
|
|
|
|
2014-05-26 17:41:37 +00:00
|
|
|
/*
|
|
|
|
* This method assumes that |iterator| is already an iterator. It will not
|
|
|
|
* check for, and call @@iterator. Callers should make sure that the passed
|
|
|
|
* in value is in fact an iterator.
|
|
|
|
*/
|
|
|
|
bool initWithIterator(JS::HandleValue aIterator);
|
|
|
|
|
2014-01-29 00:16:03 +00:00
|
|
|
/*
|
|
|
|
* Get the next value from the iterator. If false *done is true
|
|
|
|
* after this call, do not examine val.
|
|
|
|
*/
|
2014-01-29 01:54:31 +00:00
|
|
|
bool next(JS::MutableHandleValue val, bool *done);
|
2014-01-29 00:16:03 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If initialized with throwOnNonCallable = false, check whether
|
|
|
|
* the value is iterable.
|
|
|
|
*/
|
|
|
|
bool valueIsIterable() const {
|
|
|
|
return iterator;
|
|
|
|
}
|
2014-02-13 19:29:00 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
inline bool nextFromOptimizedArray(MutableHandleValue val, bool *done);
|
|
|
|
bool materializeArrayIterator();
|
2014-01-29 00:16:03 +00:00
|
|
|
};
|
|
|
|
|
2014-02-13 04:50:15 +00:00
|
|
|
|
|
|
|
/*
|
2014-11-03 21:59:31 +00:00
|
|
|
* If a large allocation fails when calling pod_{calloc,realloc}CanGC, the JS
|
|
|
|
* engine may call the large-allocation- failure callback, if set, to allow the
|
|
|
|
* embedding to flush caches, possibly perform shrinking GCs, etc. to make some
|
|
|
|
* room. The allocation will then be retried (and may still fail.)
|
2014-02-13 04:50:15 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
typedef void
|
2014-05-22 13:18:01 +00:00
|
|
|
(* LargeAllocationFailureCallback)(void *data);
|
2014-02-13 04:50:15 +00:00
|
|
|
|
|
|
|
extern JS_PUBLIC_API(void)
|
2014-05-22 13:18:01 +00:00
|
|
|
SetLargeAllocationFailureCallback(JSRuntime *rt, LargeAllocationFailureCallback afc, void *data);
|
2014-02-13 04:50:15 +00:00
|
|
|
|
2014-02-21 02:35:42 +00:00
|
|
|
/*
|
|
|
|
* Unlike the error reporter, which is only called if the exception for an OOM
|
|
|
|
* bubbles up and is not caught, the OutOfMemoryCallback is called immediately
|
|
|
|
* at the OOM site to allow the embedding to capture the current state of heap
|
|
|
|
* allocation before anything is freed. If the large-allocation-failure callback
|
|
|
|
* is called at all (not all allocation sites call the large-allocation-failure
|
|
|
|
* callback on failure), it is called before the out-of-memory callback; the
|
|
|
|
* out-of-memory callback is only called if the allocation still fails after the
|
|
|
|
* large-allocation-failure callback has returned.
|
|
|
|
*/
|
|
|
|
|
|
|
|
typedef void
|
2014-05-22 13:18:01 +00:00
|
|
|
(* OutOfMemoryCallback)(JSContext *cx, void *data);
|
2014-02-21 02:35:42 +00:00
|
|
|
|
|
|
|
extern JS_PUBLIC_API(void)
|
2014-05-22 13:18:01 +00:00
|
|
|
SetOutOfMemoryCallback(JSRuntime *rt, OutOfMemoryCallback cb, void *data);
|
2014-02-21 02:35:42 +00:00
|
|
|
|
2014-07-03 19:11:24 +00:00
|
|
|
|
|
|
|
/*
|
2015-02-26 01:06:56 +00:00
|
|
|
* Capture the current call stack as a chain of SavedFrame JSObjects, and set
|
|
|
|
* |stackp| to the SavedFrame for the youngest stack frame, or nullptr if there
|
|
|
|
* are no JS frames on the stack. If |maxFrameCount| is non-zero, capture at
|
|
|
|
* most the youngest |maxFrameCount| frames.
|
2014-07-03 19:11:24 +00:00
|
|
|
*/
|
2014-06-25 16:21:00 +00:00
|
|
|
extern JS_PUBLIC_API(bool)
|
2014-07-03 19:11:24 +00:00
|
|
|
CaptureCurrentStack(JSContext *cx, MutableHandleObject stackp, unsigned maxFrameCount = 0);
|
2014-06-25 16:21:00 +00:00
|
|
|
|
2015-02-26 01:06:56 +00:00
|
|
|
/*
|
|
|
|
* Accessors for working with SavedFrame JSObjects
|
|
|
|
*
|
|
|
|
* Each of these functions assert that if their `HandleObject savedFrame`
|
|
|
|
* argument is non-null, its JSClass is the SavedFrame class (or it is a
|
|
|
|
* cross-compartment or Xray wrapper around an object with the SavedFrame class)
|
|
|
|
* and the object is not the SavedFrame.prototype object.
|
|
|
|
*
|
|
|
|
* Each of these functions will find the first SavedFrame object in the chain
|
|
|
|
* whose underlying stack frame principals are subsumed by the cx's current
|
|
|
|
* compartment's principals, and operate on that SavedFrame object. This
|
|
|
|
* prevents leaking information about privileged frames to un-privileged
|
|
|
|
* callers. As a result, the SavedFrame in parameters do _NOT_ need to be in the
|
|
|
|
* same compartment as the cx, and the various out parameters are _NOT_
|
|
|
|
* guaranteed to be in the same compartment as cx.
|
|
|
|
*
|
|
|
|
* Additionally, it may be the case that there is no such SavedFrame object
|
|
|
|
* whose captured frame's principals are subsumed by the caller's compartment's
|
|
|
|
* principals! If the `HandleObject savedFrame` argument is null, or the
|
|
|
|
* caller's principals do not subsume any of the chained SavedFrame object's
|
|
|
|
* principals, `SavedFrameResult::AccessDenied` is returned and a (hopefully)
|
|
|
|
* sane default value is chosen for the out param.
|
|
|
|
*/
|
|
|
|
|
|
|
|
enum class SavedFrameResult {
|
|
|
|
Ok,
|
|
|
|
AccessDenied
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Given a SavedFrame JSObject, get its source property. Defaults to the empty
|
|
|
|
* string.
|
|
|
|
*/
|
|
|
|
extern JS_PUBLIC_API(SavedFrameResult)
|
|
|
|
GetSavedFrameSource(JSContext *cx, HandleObject savedFrame, MutableHandleString sourcep);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Given a SavedFrame JSObject, get its line property. Defaults to 0.
|
|
|
|
*/
|
|
|
|
extern JS_PUBLIC_API(SavedFrameResult)
|
|
|
|
GetSavedFrameLine(JSContext *cx, HandleObject savedFrame, uint32_t *linep);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Given a SavedFrame JSObject, get its column property. Defaults to 0.
|
|
|
|
*/
|
|
|
|
extern JS_PUBLIC_API(SavedFrameResult)
|
|
|
|
GetSavedFrameColumn(JSContext *cx, HandleObject savedFrame, uint32_t *columnp);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Given a SavedFrame JSObject, get its functionDisplayName string, or nullptr
|
|
|
|
* if SpiderMonkey was unable to infer a name for the captured frame's
|
|
|
|
* function. Defaults to nullptr.
|
|
|
|
*/
|
|
|
|
extern JS_PUBLIC_API(SavedFrameResult)
|
|
|
|
GetSavedFrameFunctionDisplayName(JSContext *cx, HandleObject savedFrame, MutableHandleString namep);
|
|
|
|
|
2015-02-21 11:56:00 +00:00
|
|
|
/*
|
|
|
|
* Given a SavedFrame JSObject, get its asyncCause string. Defaults to nullptr.
|
|
|
|
*/
|
|
|
|
extern JS_PUBLIC_API(SavedFrameResult)
|
|
|
|
GetSavedFrameAsyncCause(JSContext *cx, HandleObject savedFrame, MutableHandleString asyncCausep);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Given a SavedFrame JSObject, get its asyncParent SavedFrame object or nullptr
|
|
|
|
* if there is no asyncParent. The `asyncParentp` out parameter is _NOT_
|
|
|
|
* guaranteed to be in the cx's compartment. Defaults to nullptr.
|
|
|
|
*/
|
|
|
|
extern JS_PUBLIC_API(SavedFrameResult)
|
|
|
|
GetSavedFrameAsyncParent(JSContext *cx, HandleObject savedFrame, MutableHandleObject asyncParentp);
|
|
|
|
|
2015-02-26 01:06:56 +00:00
|
|
|
/*
|
|
|
|
* Given a SavedFrame JSObject, get its parent SavedFrame object or nullptr if
|
|
|
|
* it is the oldest frame in the stack. The `parentp` out parameter is _NOT_
|
|
|
|
* guaranteed to be in the cx's compartment. Defaults to nullptr.
|
|
|
|
*/
|
|
|
|
extern JS_PUBLIC_API(SavedFrameResult)
|
|
|
|
GetSavedFrameParent(JSContext *cx, HandleObject savedFrame, MutableHandleObject parentp);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Given a SavedFrame JSObject stack, stringify it in the same format as
|
|
|
|
* Error.prototype.stack. The stringified stack out parameter is placed in the
|
|
|
|
* cx's compartment. Defaults to the empty string.
|
|
|
|
*/
|
|
|
|
extern JS_PUBLIC_API(bool)
|
|
|
|
StringifySavedFrameStack(JSContext *cx, HandleObject stack, MutableHandleString stringp);
|
|
|
|
|
|
|
|
|
2013-10-15 17:13:34 +00:00
|
|
|
} /* namespace JS */
|
|
|
|
|
2013-06-20 00:59:46 +00:00
|
|
|
#endif /* jsapi_h */
|