2010-06-03 15:27:29 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
|
|
|
* vim: set ts=4 sw=4 et tw=99:
|
|
|
|
*
|
|
|
|
* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is Mozilla SpiderMonkey JavaScript 1.9 code, released
|
|
|
|
* May 28, 2008.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Mozilla Foundation
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2010
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* Andreas Gal <gal@mozilla.com>
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
|
|
|
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
|
|
|
#include "jsapi.h"
|
|
|
|
#include "jscntxt.h"
|
2012-05-01 14:30:18 -07:00
|
|
|
#include "jscompartment.h"
|
2011-07-13 04:46:23 -07:00
|
|
|
#include "jsexn.h"
|
2011-04-15 16:56:08 -07:00
|
|
|
#include "jsgc.h"
|
2010-06-03 15:27:29 -07:00
|
|
|
#include "jsiter.h"
|
|
|
|
#include "jsnum.h"
|
|
|
|
#include "jswrapper.h"
|
2012-05-01 14:30:18 -07:00
|
|
|
|
2010-08-05 17:15:49 -07:00
|
|
|
#ifdef JS_METHODJIT
|
|
|
|
# include "assembler/jit/ExecutableAllocator.h"
|
|
|
|
#endif
|
2012-05-01 14:30:18 -07:00
|
|
|
#include "gc/Marking.h"
|
|
|
|
#include "methodjit/PolyIC.h"
|
|
|
|
#include "methodjit/MonoIC.h"
|
2010-06-03 15:27:29 -07:00
|
|
|
|
|
|
|
#include "jsobjinlines.h"
|
|
|
|
|
2012-02-01 13:36:48 -08:00
|
|
|
#include "vm/RegExpObject-inl.h"
|
|
|
|
|
2010-06-03 15:27:29 -07:00
|
|
|
using namespace js;
|
2010-09-24 10:54:39 -07:00
|
|
|
using namespace js::gc;
|
2010-06-03 15:27:29 -07:00
|
|
|
|
2012-02-21 10:31:35 -08:00
|
|
|
namespace js {
|
|
|
|
int sWrapperFamily;
|
|
|
|
}
|
2010-09-20 14:48:01 -07:00
|
|
|
|
|
|
|
void *
|
2011-09-08 20:29:15 -07:00
|
|
|
Wrapper::getWrapperFamily()
|
2010-09-20 14:48:01 -07:00
|
|
|
{
|
|
|
|
return &sWrapperFamily;
|
|
|
|
}
|
2010-06-24 14:45:32 -07:00
|
|
|
|
2011-10-04 07:06:54 -07:00
|
|
|
JS_FRIEND_API(JSObject *)
|
2012-02-28 15:11:11 -08:00
|
|
|
js::UnwrapObject(JSObject *wrapped, bool stopAtOuter, unsigned *flagsp)
|
2010-06-24 14:45:32 -07:00
|
|
|
{
|
2012-02-28 15:11:11 -08:00
|
|
|
unsigned flags = 0;
|
2012-05-14 14:30:07 -07:00
|
|
|
while (wrapped->isWrapper() &&
|
|
|
|
!JS_UNLIKELY(stopAtOuter && wrapped->getClass()->ext.innerObject)) {
|
2011-10-04 07:06:54 -07:00
|
|
|
flags |= static_cast<Wrapper *>(GetProxyHandler(wrapped))->flags();
|
|
|
|
wrapped = GetProxyPrivate(wrapped).toObjectOrNull();
|
2010-07-02 13:54:53 -07:00
|
|
|
}
|
|
|
|
if (flagsp)
|
|
|
|
*flagsp = flags;
|
2010-06-24 14:45:32 -07:00
|
|
|
return wrapped;
|
|
|
|
}
|
|
|
|
|
2012-03-23 14:59:27 -07:00
|
|
|
JS_FRIEND_API(JSObject *)
|
|
|
|
js::UnwrapObjectChecked(JSContext *cx, JSObject *obj)
|
|
|
|
{
|
2012-05-14 14:30:07 -07:00
|
|
|
while (obj->isWrapper() &&
|
|
|
|
!JS_UNLIKELY(!!obj->getClass()->ext.innerObject)) {
|
2012-03-23 14:59:27 -07:00
|
|
|
JSObject *wrapper = obj;
|
2012-04-19 11:19:41 -07:00
|
|
|
AbstractWrapper *handler = AbstractWrapper::wrapperHandler(obj);
|
2012-03-23 14:59:27 -07:00
|
|
|
bool rvOnFailure;
|
|
|
|
if (!handler->enter(cx, wrapper, JSID_VOID,
|
|
|
|
Wrapper::PUNCTURE, &rvOnFailure))
|
|
|
|
return rvOnFailure ? obj : NULL;
|
|
|
|
obj = Wrapper::wrappedObject(obj);
|
|
|
|
JS_ASSERT(obj);
|
|
|
|
handler->leave(cx, wrapper);
|
|
|
|
}
|
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
2011-10-04 07:06:54 -07:00
|
|
|
bool
|
|
|
|
js::IsCrossCompartmentWrapper(const JSObject *wrapper)
|
|
|
|
{
|
|
|
|
return wrapper->isWrapper() &&
|
|
|
|
!!(Wrapper::wrapperHandler(wrapper)->flags() & Wrapper::CROSS_COMPARTMENT);
|
|
|
|
}
|
|
|
|
|
2012-04-19 11:19:41 -07:00
|
|
|
AbstractWrapper::AbstractWrapper(unsigned flags) :
|
|
|
|
ProxyHandler(&sWrapperFamily),
|
|
|
|
mFlags(flags)
|
2012-04-15 16:43:14 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-04-19 11:19:41 -07:00
|
|
|
Wrapper::Wrapper(unsigned flags) : AbstractWrapper(flags)
|
2010-06-03 15:27:29 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2011-09-08 20:29:15 -07:00
|
|
|
Wrapper::~Wrapper()
|
2010-06-03 15:27:29 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2010-09-17 14:54:40 -07:00
|
|
|
#define CHECKED(op, act) \
|
2010-07-02 13:54:53 -07:00
|
|
|
JS_BEGIN_MACRO \
|
2011-01-29 18:48:30 -08:00
|
|
|
bool status; \
|
|
|
|
if (!enter(cx, wrapper, id, act, &status)) \
|
|
|
|
return status; \
|
2010-07-02 13:54:53 -07:00
|
|
|
bool ok = (op); \
|
|
|
|
leave(cx, wrapper); \
|
|
|
|
return ok; \
|
|
|
|
JS_END_MACRO
|
|
|
|
|
2010-09-17 14:54:40 -07:00
|
|
|
#define SET(action) CHECKED(action, SET)
|
|
|
|
#define GET(action) CHECKED(action, GET)
|
2010-07-02 13:54:53 -07:00
|
|
|
|
2010-06-03 15:27:29 -07:00
|
|
|
bool
|
2012-04-15 16:43:14 -07:00
|
|
|
AbstractWrapper::getPropertyDescriptor(JSContext *cx, JSObject *wrapper, jsid id, bool set,
|
|
|
|
PropertyDescriptor *desc)
|
2010-06-03 15:27:29 -07:00
|
|
|
{
|
2011-03-03 12:50:40 -08:00
|
|
|
desc->obj = NULL; // default result if we refuse to perform this action
|
2011-09-20 11:40:24 -07:00
|
|
|
CHECKED(JS_GetPropertyDescriptorById(cx, wrappedObject(wrapper), id, JSRESOLVE_QUALIFIED, desc),
|
|
|
|
set ? SET : GET);
|
2010-07-02 13:54:53 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
2012-02-28 15:11:11 -08:00
|
|
|
GetOwnPropertyDescriptor(JSContext *cx, JSObject *obj, jsid id, unsigned flags, JSPropertyDescriptor *desc)
|
2010-07-02 13:54:53 -07:00
|
|
|
{
|
2011-06-28 14:00:19 -07:00
|
|
|
// If obj is a proxy, we can do better than just guessing. This is
|
|
|
|
// important for certain types of wrappers that wrap other wrappers.
|
2011-09-20 11:40:24 -07:00
|
|
|
if (obj->isProxy())
|
2011-09-08 20:29:15 -07:00
|
|
|
return Proxy::getOwnPropertyDescriptor(cx, obj, id, flags & JSRESOLVE_ASSIGNING, desc);
|
2011-06-28 14:00:19 -07:00
|
|
|
|
2010-07-02 13:54:53 -07:00
|
|
|
if (!JS_GetPropertyDescriptorById(cx, obj, id, flags, desc))
|
|
|
|
return false;
|
|
|
|
if (desc->obj != obj)
|
|
|
|
desc->obj = NULL;
|
|
|
|
return true;
|
2010-06-03 15:27:29 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2012-04-15 16:43:14 -07:00
|
|
|
AbstractWrapper::getOwnPropertyDescriptor(JSContext *cx, JSObject *wrapper, jsid id, bool set,
|
|
|
|
PropertyDescriptor *desc)
|
2010-06-03 15:27:29 -07:00
|
|
|
{
|
2011-06-28 14:00:19 -07:00
|
|
|
desc->obj = NULL; // default result if we refuse to perform this action
|
2011-09-20 11:40:24 -07:00
|
|
|
CHECKED(GetOwnPropertyDescriptor(cx, wrappedObject(wrapper), id, JSRESOLVE_QUALIFIED, desc),
|
|
|
|
set ? SET : GET);
|
2010-06-03 15:27:29 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2012-04-15 16:43:14 -07:00
|
|
|
AbstractWrapper::defineProperty(JSContext *cx, JSObject *wrapper, jsid id, PropertyDescriptor *desc)
|
2010-06-03 15:27:29 -07:00
|
|
|
{
|
2011-09-20 11:40:24 -07:00
|
|
|
SET(JS_DefinePropertyById(cx, wrappedObject(wrapper), id, desc->value,
|
|
|
|
desc->getter, desc->setter, desc->attrs));
|
2010-06-03 15:27:29 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2012-04-15 16:43:14 -07:00
|
|
|
AbstractWrapper::getOwnPropertyNames(JSContext *cx, JSObject *wrapper, AutoIdVector &props)
|
2010-06-03 15:27:29 -07:00
|
|
|
{
|
2011-01-29 18:48:30 -08:00
|
|
|
// if we refuse to perform this action, props remains empty
|
2010-07-14 23:19:36 -07:00
|
|
|
jsid id = JSID_VOID;
|
2010-09-21 11:35:29 -07:00
|
|
|
GET(GetPropertyNames(cx, wrappedObject(wrapper), JSITER_OWNONLY | JSITER_HIDDEN, &props));
|
2010-06-03 15:27:29 -07:00
|
|
|
}
|
|
|
|
|
2010-07-02 13:54:53 -07:00
|
|
|
static bool
|
2010-07-14 23:19:36 -07:00
|
|
|
ValueToBoolean(Value *vp, bool *bp)
|
2010-06-03 15:27:29 -07:00
|
|
|
{
|
2010-07-02 13:54:53 -07:00
|
|
|
*bp = js_ValueToBoolean(*vp);
|
2010-07-01 18:06:33 -07:00
|
|
|
return true;
|
2010-06-03 15:27:29 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2012-04-15 16:43:14 -07:00
|
|
|
AbstractWrapper::delete_(JSContext *cx, JSObject *wrapper, jsid id, bool *bp)
|
2010-07-01 15:45:08 -07:00
|
|
|
{
|
2011-01-29 18:48:30 -08:00
|
|
|
*bp = true; // default result if we refuse to perform this action
|
2010-07-14 23:19:36 -07:00
|
|
|
Value v;
|
2011-09-20 11:40:24 -07:00
|
|
|
SET(JS_DeletePropertyById2(cx, wrappedObject(wrapper), id, &v) &&
|
2010-07-02 13:54:53 -07:00
|
|
|
ValueToBoolean(&v, bp));
|
2010-07-01 15:45:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2012-04-15 16:43:14 -07:00
|
|
|
AbstractWrapper::enumerate(JSContext *cx, JSObject *wrapper, AutoIdVector &props)
|
2010-07-02 13:54:53 -07:00
|
|
|
{
|
2011-01-29 18:48:30 -08:00
|
|
|
// if we refuse to perform this action, props remains empty
|
2010-07-14 23:19:36 -07:00
|
|
|
static jsid id = JSID_VOID;
|
2010-09-21 11:35:29 -07:00
|
|
|
GET(GetPropertyNames(cx, wrappedObject(wrapper), 0, &props));
|
2010-07-02 13:54:53 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
|
|
|
Cond(JSBool b, bool *bp)
|
|
|
|
{
|
|
|
|
*bp = !!b;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-06-03 15:27:29 -07:00
|
|
|
bool
|
2011-09-08 20:29:15 -07:00
|
|
|
Wrapper::has(JSContext *cx, JSObject *wrapper, jsid id, bool *bp)
|
2010-06-03 15:27:29 -07:00
|
|
|
{
|
2011-01-29 18:48:30 -08:00
|
|
|
*bp = false; // default result if we refuse to perform this action
|
2010-06-03 15:27:29 -07:00
|
|
|
JSBool found;
|
2010-07-02 13:54:53 -07:00
|
|
|
GET(JS_HasPropertyById(cx, wrappedObject(wrapper), id, &found) &&
|
|
|
|
Cond(found, bp));
|
2010-06-03 15:27:29 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2011-09-08 20:29:15 -07:00
|
|
|
Wrapper::hasOwn(JSContext *cx, JSObject *wrapper, jsid id, bool *bp)
|
2010-06-03 15:27:29 -07:00
|
|
|
{
|
2011-01-29 18:48:30 -08:00
|
|
|
*bp = false; // default result if we refuse to perform this action
|
2010-07-14 23:19:36 -07:00
|
|
|
PropertyDescriptor desc;
|
2010-07-02 13:54:53 -07:00
|
|
|
JSObject *wobj = wrappedObject(wrapper);
|
2011-09-20 11:40:24 -07:00
|
|
|
GET(JS_GetPropertyDescriptorById(cx, wobj, id, JSRESOLVE_QUALIFIED, &desc) &&
|
2010-07-02 13:54:53 -07:00
|
|
|
Cond(desc.obj == wobj, bp));
|
2010-06-03 15:27:29 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2011-09-08 20:29:15 -07:00
|
|
|
Wrapper::get(JSContext *cx, JSObject *wrapper, JSObject *receiver, jsid id, Value *vp)
|
2010-06-03 15:27:29 -07:00
|
|
|
{
|
2011-01-29 18:48:30 -08:00
|
|
|
vp->setUndefined(); // default result if we refuse to perform this action
|
2011-09-15 11:44:10 -07:00
|
|
|
GET(wrappedObject(wrapper)->getGeneric(cx, receiver, id, vp));
|
2010-06-03 15:27:29 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2011-09-08 20:29:15 -07:00
|
|
|
Wrapper::set(JSContext *cx, JSObject *wrapper, JSObject *receiver, jsid id, bool strict,
|
2011-02-09 11:31:40 -08:00
|
|
|
Value *vp)
|
2010-06-03 15:27:29 -07:00
|
|
|
{
|
2012-03-16 12:47:21 -07:00
|
|
|
SET(wrappedObject(wrapper)->setGeneric(cx, id, vp, strict));
|
2010-07-01 15:45:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2011-09-08 20:29:15 -07:00
|
|
|
Wrapper::keys(JSContext *cx, JSObject *wrapper, AutoIdVector &props)
|
2010-07-01 15:45:08 -07:00
|
|
|
{
|
2011-01-29 18:48:30 -08:00
|
|
|
// if we refuse to perform this action, props remains empty
|
2010-07-14 23:19:36 -07:00
|
|
|
const jsid id = JSID_VOID;
|
2010-09-21 11:35:29 -07:00
|
|
|
GET(GetPropertyNames(cx, wrappedObject(wrapper), JSITER_OWNONLY, &props));
|
2010-07-01 15:45:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2012-02-28 15:11:11 -08:00
|
|
|
Wrapper::iterate(JSContext *cx, JSObject *wrapper, unsigned flags, Value *vp)
|
2010-07-01 15:45:08 -07:00
|
|
|
{
|
2011-01-29 18:48:30 -08:00
|
|
|
vp->setUndefined(); // default result if we refuse to perform this action
|
2010-07-14 23:19:36 -07:00
|
|
|
const jsid id = JSID_VOID;
|
2012-04-12 09:23:51 -07:00
|
|
|
GET(GetIterator(cx, RootedVarObject(cx, wrappedObject(wrapper)), flags, vp));
|
2010-07-02 13:54:53 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2012-02-28 15:11:11 -08:00
|
|
|
Wrapper::call(JSContext *cx, JSObject *wrapper, unsigned argc, Value *vp)
|
2010-07-02 13:54:53 -07:00
|
|
|
{
|
2011-01-29 18:48:30 -08:00
|
|
|
vp->setUndefined(); // default result if we refuse to perform this action
|
2010-07-14 23:19:36 -07:00
|
|
|
const jsid id = JSID_VOID;
|
2011-09-08 20:29:15 -07:00
|
|
|
CHECKED(ProxyHandler::call(cx, wrapper, argc, vp), CALL);
|
2010-07-02 13:54:53 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2012-02-28 15:11:11 -08:00
|
|
|
Wrapper::construct(JSContext *cx, JSObject *wrapper, unsigned argc, Value *argv, Value *vp)
|
2010-07-02 13:54:53 -07:00
|
|
|
{
|
2011-01-29 18:48:30 -08:00
|
|
|
vp->setUndefined(); // default result if we refuse to perform this action
|
2010-07-14 23:19:36 -07:00
|
|
|
const jsid id = JSID_VOID;
|
2011-09-08 20:29:15 -07:00
|
|
|
GET(ProxyHandler::construct(cx, wrapper, argc, argv, vp));
|
2010-07-02 13:54:53 -07:00
|
|
|
}
|
|
|
|
|
2011-10-04 10:50:25 -07:00
|
|
|
bool
|
|
|
|
Wrapper::nativeCall(JSContext *cx, JSObject *wrapper, Class *clasp, Native native, CallArgs args)
|
|
|
|
{
|
|
|
|
const jsid id = JSID_VOID;
|
|
|
|
CHECKED(CallJSNative(cx, native, args), CALL);
|
|
|
|
}
|
|
|
|
|
2010-10-10 15:39:26 -07:00
|
|
|
bool
|
2011-09-08 20:29:15 -07:00
|
|
|
Wrapper::hasInstance(JSContext *cx, JSObject *wrapper, const Value *vp, bool *bp)
|
2010-10-10 15:39:26 -07:00
|
|
|
{
|
2011-05-17 00:25:06 -07:00
|
|
|
*bp = false; // default result if we refuse to perform this action
|
2010-10-10 15:39:26 -07:00
|
|
|
const jsid id = JSID_VOID;
|
2011-05-17 00:25:06 -07:00
|
|
|
JSBool b = JS_FALSE;
|
2011-09-20 11:40:24 -07:00
|
|
|
GET(JS_HasInstance(cx, wrappedObject(wrapper), *vp, &b) && Cond(b, bp));
|
2010-10-10 15:39:26 -07:00
|
|
|
}
|
|
|
|
|
2010-11-10 15:56:00 -08:00
|
|
|
JSType
|
2011-09-08 20:29:15 -07:00
|
|
|
Wrapper::typeOf(JSContext *cx, JSObject *wrapper)
|
2010-11-10 15:56:00 -08:00
|
|
|
{
|
|
|
|
return TypeOfValue(cx, ObjectValue(*wrappedObject(wrapper)));
|
|
|
|
}
|
|
|
|
|
2011-09-20 16:48:50 -07:00
|
|
|
bool
|
2011-09-28 08:48:16 -07:00
|
|
|
Wrapper::objectClassIs(JSObject *wrapper, ESClassValue classValue, JSContext *cx)
|
2011-09-20 16:48:50 -07:00
|
|
|
{
|
|
|
|
return ObjectClassIs(*wrappedObject(wrapper), classValue, cx);
|
|
|
|
}
|
|
|
|
|
2010-07-02 13:54:53 -07:00
|
|
|
JSString *
|
2011-09-08 20:29:15 -07:00
|
|
|
Wrapper::obj_toString(JSContext *cx, JSObject *wrapper)
|
2010-07-02 13:54:53 -07:00
|
|
|
{
|
2011-01-29 18:48:30 -08:00
|
|
|
bool status;
|
|
|
|
if (!enter(cx, wrapper, JSID_VOID, GET, &status)) {
|
|
|
|
if (status) {
|
|
|
|
// Perform some default behavior that doesn't leak any information.
|
|
|
|
return JS_NewStringCopyZ(cx, "[object Object]");
|
|
|
|
}
|
2010-07-02 13:54:53 -07:00
|
|
|
return NULL;
|
2011-01-29 18:48:30 -08:00
|
|
|
}
|
|
|
|
JSString *str = obj_toStringHelper(cx, wrappedObject(wrapper));
|
2010-07-02 13:54:53 -07:00
|
|
|
leave(cx, wrapper);
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
|
|
|
JSString *
|
2012-02-28 15:11:11 -08:00
|
|
|
Wrapper::fun_toString(JSContext *cx, JSObject *wrapper, unsigned indent)
|
2010-07-02 13:54:53 -07:00
|
|
|
{
|
2011-01-29 18:48:30 -08:00
|
|
|
bool status;
|
|
|
|
if (!enter(cx, wrapper, JSID_VOID, GET, &status)) {
|
|
|
|
if (status) {
|
|
|
|
// Perform some default behavior that doesn't leak any information.
|
|
|
|
if (wrapper->isCallable())
|
|
|
|
return JS_NewStringCopyZ(cx, "function () {\n [native code]\n}");
|
|
|
|
js::Value v = ObjectValue(*wrapper);
|
|
|
|
js_ReportIsNotFunction(cx, &v, 0);
|
|
|
|
return NULL;
|
|
|
|
}
|
2010-07-02 13:54:53 -07:00
|
|
|
return NULL;
|
2011-01-29 18:48:30 -08:00
|
|
|
}
|
2011-09-08 20:29:15 -07:00
|
|
|
JSString *str = ProxyHandler::fun_toString(cx, wrapper, indent);
|
2010-07-02 13:54:53 -07:00
|
|
|
leave(cx, wrapper);
|
|
|
|
return str;
|
2010-06-03 15:27:29 -07:00
|
|
|
}
|
|
|
|
|
2012-02-23 13:51:19 -08:00
|
|
|
bool
|
|
|
|
Wrapper::regexp_toShared(JSContext *cx, JSObject *wrapper, RegExpGuard *g)
|
2012-02-01 13:36:48 -08:00
|
|
|
{
|
2012-04-25 18:18:46 -07:00
|
|
|
return RegExpToShared(cx, *wrappedObject(wrapper), g);
|
2012-02-01 13:36:48 -08:00
|
|
|
}
|
|
|
|
|
2011-04-01 15:24:21 -07:00
|
|
|
bool
|
2011-09-08 20:29:15 -07:00
|
|
|
Wrapper::defaultValue(JSContext *cx, JSObject *wrapper, JSType hint, Value *vp)
|
2011-04-01 15:24:21 -07:00
|
|
|
{
|
|
|
|
*vp = ObjectValue(*wrappedObject(wrapper));
|
|
|
|
if (hint == JSTYPE_VOID)
|
|
|
|
return ToPrimitive(cx, vp);
|
|
|
|
return ToPrimitive(cx, hint, vp);
|
|
|
|
}
|
|
|
|
|
2012-02-07 10:57:16 -08:00
|
|
|
bool
|
|
|
|
Wrapper::iteratorNext(JSContext *cx, JSObject *wrapper, Value *vp)
|
|
|
|
{
|
2012-04-12 09:23:51 -07:00
|
|
|
if (!js_IteratorMore(cx, RootedVarObject(cx, wrappedObject(wrapper)), vp))
|
2012-02-07 10:57:16 -08:00
|
|
|
return false;
|
|
|
|
|
|
|
|
if (vp->toBoolean()) {
|
|
|
|
*vp = cx->iterValue;
|
|
|
|
cx->iterValue.setUndefined();
|
|
|
|
} else {
|
|
|
|
vp->setMagic(JS_NO_ITER_VALUE);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-06-03 15:27:29 -07:00
|
|
|
void
|
2011-09-08 20:29:15 -07:00
|
|
|
Wrapper::trace(JSTracer *trc, JSObject *wrapper)
|
2010-06-03 15:27:29 -07:00
|
|
|
{
|
2012-02-17 18:43:48 -08:00
|
|
|
MarkSlot(trc, &wrapper->getReservedSlotRef(JSSLOT_PROXY_PRIVATE), "wrappedObject");
|
2010-06-03 15:27:29 -07:00
|
|
|
}
|
|
|
|
|
2011-04-08 19:51:40 -07:00
|
|
|
JSObject *
|
2012-04-15 16:43:14 -07:00
|
|
|
AbstractWrapper::wrappedObject(const JSObject *wrapper)
|
2011-04-08 19:51:40 -07:00
|
|
|
{
|
2011-10-04 07:06:54 -07:00
|
|
|
return GetProxyPrivate(wrapper).toObjectOrNull();
|
2011-04-08 19:51:40 -07:00
|
|
|
}
|
|
|
|
|
2012-04-19 11:19:41 -07:00
|
|
|
AbstractWrapper *
|
2012-04-15 16:43:14 -07:00
|
|
|
AbstractWrapper::wrapperHandler(const JSObject *wrapper)
|
2011-04-08 19:51:40 -07:00
|
|
|
{
|
2012-04-19 11:19:41 -07:00
|
|
|
JS_ASSERT(wrapper->isWrapper());
|
|
|
|
return static_cast<AbstractWrapper *>(GetProxyHandler(wrapper));
|
2011-04-08 19:51:40 -07:00
|
|
|
}
|
|
|
|
|
2010-07-02 13:54:53 -07:00
|
|
|
bool
|
2012-04-15 16:43:14 -07:00
|
|
|
AbstractWrapper::enter(JSContext *cx, JSObject *wrapper, jsid id, Action act, bool *bp)
|
2010-07-02 13:54:53 -07:00
|
|
|
{
|
2011-01-29 18:48:30 -08:00
|
|
|
*bp = true;
|
2010-07-02 13:54:53 -07:00
|
|
|
return true;
|
|
|
|
}
|
2010-06-24 14:45:32 -07:00
|
|
|
|
2010-07-02 13:54:53 -07:00
|
|
|
void
|
2012-04-15 16:43:14 -07:00
|
|
|
AbstractWrapper::leave(JSContext *cx, JSObject *wrapper)
|
2010-07-02 13:54:53 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-02-28 15:11:11 -08:00
|
|
|
Wrapper Wrapper::singleton((unsigned)0);
|
2010-06-23 14:35:10 -07:00
|
|
|
|
|
|
|
JSObject *
|
2011-09-08 20:29:15 -07:00
|
|
|
Wrapper::New(JSContext *cx, JSObject *obj, JSObject *proto, JSObject *parent, Wrapper *handler)
|
2010-06-03 15:27:29 -07:00
|
|
|
{
|
2010-11-01 18:28:14 -07:00
|
|
|
JS_ASSERT(parent);
|
2012-05-14 16:53:30 -07:00
|
|
|
#if JS_HAS_XML_SUPPORT
|
2010-11-10 15:56:00 -08:00
|
|
|
if (obj->isXML()) {
|
|
|
|
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_CANT_WRAP_XML_OBJECT);
|
|
|
|
return NULL;
|
|
|
|
}
|
2012-05-14 16:53:30 -07:00
|
|
|
#endif
|
|
|
|
|
2010-07-14 23:19:36 -07:00
|
|
|
return NewProxyObject(cx, handler, ObjectValue(*obj), proto, parent,
|
2010-06-23 14:35:10 -07:00
|
|
|
obj->isCallable() ? obj : NULL, NULL);
|
2010-06-03 15:27:29 -07:00
|
|
|
}
|
|
|
|
|
2010-06-24 14:45:32 -07:00
|
|
|
/* Compartments. */
|
2010-06-23 14:35:10 -07:00
|
|
|
|
2010-06-24 14:45:32 -07:00
|
|
|
namespace js {
|
2010-06-03 15:27:29 -07:00
|
|
|
|
2010-06-24 14:45:32 -07:00
|
|
|
extern JSObject *
|
2010-09-17 14:54:40 -07:00
|
|
|
TransparentObjectWrapper(JSContext *cx, JSObject *obj, JSObject *wrappedProto, JSObject *parent,
|
2012-02-28 15:11:11 -08:00
|
|
|
unsigned flags)
|
2010-06-23 14:35:10 -07:00
|
|
|
{
|
2010-08-23 15:34:11 -07:00
|
|
|
// Allow wrapping outer window proxies.
|
|
|
|
JS_ASSERT(!obj->isWrapper() || obj->getClass()->ext.innerObject);
|
2011-09-08 20:29:15 -07:00
|
|
|
return Wrapper::New(cx, obj, wrappedProto, parent, &CrossCompartmentWrapper::singleton);
|
2010-06-23 14:35:10 -07:00
|
|
|
}
|
|
|
|
|
2010-06-24 14:45:32 -07:00
|
|
|
}
|
2010-06-23 14:35:10 -07:00
|
|
|
|
2011-05-02 15:47:10 -07:00
|
|
|
ForceFrame::ForceFrame(JSContext *cx, JSObject *target)
|
|
|
|
: context(cx),
|
2011-06-07 16:43:18 -07:00
|
|
|
target(target),
|
|
|
|
frame(NULL)
|
2011-05-02 15:47:10 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2011-05-24 08:45:36 -07:00
|
|
|
ForceFrame::~ForceFrame()
|
|
|
|
{
|
2011-06-07 16:43:18 -07:00
|
|
|
context->delete_(frame);
|
2011-05-24 08:45:36 -07:00
|
|
|
}
|
|
|
|
|
2011-05-02 15:47:10 -07:00
|
|
|
bool
|
|
|
|
ForceFrame::enter()
|
|
|
|
{
|
2011-06-07 16:43:18 -07:00
|
|
|
frame = context->new_<DummyFrameGuard>();
|
|
|
|
if (!frame)
|
|
|
|
return false;
|
2011-05-02 15:47:10 -07:00
|
|
|
|
|
|
|
JS_ASSERT(context->compartment == target->compartment());
|
2011-08-05 14:06:33 -07:00
|
|
|
JSCompartment *destination = context->compartment;
|
2011-05-02 15:47:10 -07:00
|
|
|
|
2012-01-02 15:02:05 -08:00
|
|
|
JSObject &scopeChain = target->global();
|
|
|
|
JS_ASSERT(scopeChain.isNative());
|
2011-05-02 15:47:10 -07:00
|
|
|
|
2012-01-02 15:02:05 -08:00
|
|
|
return context->stack.pushDummyFrame(context, destination, scopeChain, frame);
|
2011-05-02 15:47:10 -07:00
|
|
|
}
|
|
|
|
|
2010-06-23 14:35:10 -07:00
|
|
|
AutoCompartment::AutoCompartment(JSContext *cx, JSObject *target)
|
|
|
|
: context(cx),
|
|
|
|
origin(cx->compartment),
|
|
|
|
target(target),
|
2011-10-04 07:06:54 -07:00
|
|
|
destination(target->compartment()),
|
2010-07-20 16:59:29 -07:00
|
|
|
entered(false)
|
2010-06-23 14:35:10 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
AutoCompartment::~AutoCompartment()
|
|
|
|
{
|
2010-07-20 16:59:29 -07:00
|
|
|
if (entered)
|
2010-06-23 14:35:10 -07:00
|
|
|
leave();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
AutoCompartment::enter()
|
|
|
|
{
|
2010-07-20 16:59:29 -07:00
|
|
|
JS_ASSERT(!entered);
|
|
|
|
if (origin != destination) {
|
2012-01-02 15:02:05 -08:00
|
|
|
JSObject &scopeChain = target->global();
|
|
|
|
JS_ASSERT(scopeChain.isNative());
|
2011-01-07 09:13:00 -08:00
|
|
|
|
2010-07-20 16:59:29 -07:00
|
|
|
frame.construct();
|
2012-01-02 15:02:05 -08:00
|
|
|
if (!context->stack.pushDummyFrame(context, destination, scopeChain, &frame.ref()))
|
2010-07-20 16:59:29 -07:00
|
|
|
return false;
|
2011-01-17 14:21:03 -08:00
|
|
|
|
|
|
|
if (context->isExceptionPending())
|
|
|
|
context->wrapPendingException();
|
2010-06-23 14:35:10 -07:00
|
|
|
}
|
2010-07-20 16:59:29 -07:00
|
|
|
entered = true;
|
|
|
|
return true;
|
2010-06-23 14:35:10 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
AutoCompartment::leave()
|
|
|
|
{
|
2010-07-20 16:59:29 -07:00
|
|
|
JS_ASSERT(entered);
|
|
|
|
if (origin != destination) {
|
|
|
|
frame.destroy();
|
2010-09-27 18:24:24 -07:00
|
|
|
context->resetCompartment();
|
2010-07-20 16:59:29 -07:00
|
|
|
}
|
|
|
|
entered = false;
|
2010-06-23 14:35:10 -07:00
|
|
|
}
|
|
|
|
|
2011-07-13 04:46:23 -07:00
|
|
|
ErrorCopier::~ErrorCopier()
|
|
|
|
{
|
|
|
|
JSContext *cx = ac.context;
|
|
|
|
if (cx->compartment == ac.destination &&
|
|
|
|
ac.origin != ac.destination &&
|
|
|
|
cx->isExceptionPending())
|
|
|
|
{
|
|
|
|
Value exc = cx->getPendingException();
|
2011-08-18 10:30:19 -07:00
|
|
|
if (exc.isObject() && exc.toObject().isError() && exc.toObject().getPrivate()) {
|
2011-07-13 04:46:23 -07:00
|
|
|
cx->clearPendingException();
|
|
|
|
ac.leave();
|
2012-04-30 17:10:30 -07:00
|
|
|
JSObject *copyobj = js_CopyErrorObject(cx, RootedVarObject(cx, &exc.toObject()), scope);
|
2011-07-13 04:46:23 -07:00
|
|
|
if (copyobj)
|
|
|
|
cx->setPendingException(ObjectValue(*copyobj));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-24 14:45:32 -07:00
|
|
|
/* Cross compartment wrappers. */
|
2010-06-23 14:35:10 -07:00
|
|
|
|
2012-02-28 15:11:11 -08:00
|
|
|
CrossCompartmentWrapper::CrossCompartmentWrapper(unsigned flags)
|
2011-09-08 20:29:15 -07:00
|
|
|
: Wrapper(CROSS_COMPARTMENT | flags)
|
2010-06-24 14:45:32 -07:00
|
|
|
{
|
|
|
|
}
|
2010-06-23 14:35:10 -07:00
|
|
|
|
2011-09-08 20:29:15 -07:00
|
|
|
CrossCompartmentWrapper::~CrossCompartmentWrapper()
|
2010-06-23 14:35:10 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2010-07-02 13:54:53 -07:00
|
|
|
#define PIERCE(cx, wrapper, mode, pre, op, post) \
|
|
|
|
JS_BEGIN_MACRO \
|
|
|
|
AutoCompartment call(cx, wrappedObject(wrapper)); \
|
|
|
|
if (!call.enter()) \
|
|
|
|
return false; \
|
|
|
|
bool ok = (pre) && (op); \
|
|
|
|
call.leave(); \
|
|
|
|
return ok && (post); \
|
2010-06-24 14:45:32 -07:00
|
|
|
JS_END_MACRO
|
|
|
|
|
|
|
|
#define NOTHING (true)
|
|
|
|
|
2010-06-23 14:35:10 -07:00
|
|
|
bool
|
2011-09-08 20:29:15 -07:00
|
|
|
CrossCompartmentWrapper::getPropertyDescriptor(JSContext *cx, JSObject *wrapper, jsid id,
|
|
|
|
bool set, PropertyDescriptor *desc)
|
2010-06-23 14:35:10 -07:00
|
|
|
{
|
2010-09-17 14:54:41 -07:00
|
|
|
PIERCE(cx, wrapper, set ? SET : GET,
|
2010-06-23 14:35:10 -07:00
|
|
|
call.destination->wrapId(cx, &id),
|
2011-09-08 20:29:15 -07:00
|
|
|
Wrapper::getPropertyDescriptor(cx, wrapper, id, set, desc),
|
2010-06-23 14:35:10 -07:00
|
|
|
call.origin->wrap(cx, desc));
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2011-09-08 20:29:15 -07:00
|
|
|
CrossCompartmentWrapper::getOwnPropertyDescriptor(JSContext *cx, JSObject *wrapper, jsid id,
|
|
|
|
bool set, PropertyDescriptor *desc)
|
2010-06-23 14:35:10 -07:00
|
|
|
{
|
2010-09-17 14:54:41 -07:00
|
|
|
PIERCE(cx, wrapper, set ? SET : GET,
|
2010-06-23 14:35:10 -07:00
|
|
|
call.destination->wrapId(cx, &id),
|
2011-09-08 20:29:15 -07:00
|
|
|
Wrapper::getOwnPropertyDescriptor(cx, wrapper, id, set, desc),
|
2010-06-23 14:35:10 -07:00
|
|
|
call.origin->wrap(cx, desc));
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2011-09-08 20:29:15 -07:00
|
|
|
CrossCompartmentWrapper::defineProperty(JSContext *cx, JSObject *wrapper, jsid id, PropertyDescriptor *desc)
|
2010-06-23 14:35:10 -07:00
|
|
|
{
|
2010-07-14 23:19:36 -07:00
|
|
|
AutoPropertyDescriptorRooter desc2(cx, desc);
|
2010-07-02 13:54:53 -07:00
|
|
|
PIERCE(cx, wrapper, SET,
|
2010-06-23 14:35:10 -07:00
|
|
|
call.destination->wrapId(cx, &id) && call.destination->wrap(cx, &desc2),
|
2011-09-08 20:29:15 -07:00
|
|
|
Wrapper::defineProperty(cx, wrapper, id, &desc2),
|
2010-06-23 14:35:10 -07:00
|
|
|
NOTHING);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2011-09-08 20:29:15 -07:00
|
|
|
CrossCompartmentWrapper::getOwnPropertyNames(JSContext *cx, JSObject *wrapper, AutoIdVector &props)
|
2010-06-23 14:35:10 -07:00
|
|
|
{
|
2010-07-02 13:54:53 -07:00
|
|
|
PIERCE(cx, wrapper, GET,
|
2010-06-23 14:35:10 -07:00
|
|
|
NOTHING,
|
2011-09-08 20:29:15 -07:00
|
|
|
Wrapper::getOwnPropertyNames(cx, wrapper, props),
|
2010-06-25 15:58:09 -07:00
|
|
|
call.origin->wrap(cx, props));
|
2010-06-23 14:35:10 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2011-09-08 20:29:15 -07:00
|
|
|
CrossCompartmentWrapper::delete_(JSContext *cx, JSObject *wrapper, jsid id, bool *bp)
|
2010-06-23 14:35:10 -07:00
|
|
|
{
|
2010-07-02 13:54:53 -07:00
|
|
|
PIERCE(cx, wrapper, SET,
|
2010-06-23 14:35:10 -07:00
|
|
|
call.destination->wrapId(cx, &id),
|
2011-09-08 20:29:15 -07:00
|
|
|
Wrapper::delete_(cx, wrapper, id, bp),
|
2010-06-23 14:35:10 -07:00
|
|
|
NOTHING);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2011-09-08 20:29:15 -07:00
|
|
|
CrossCompartmentWrapper::enumerate(JSContext *cx, JSObject *wrapper, AutoIdVector &props)
|
2010-06-23 14:35:10 -07:00
|
|
|
{
|
2010-07-02 13:54:53 -07:00
|
|
|
PIERCE(cx, wrapper, GET,
|
2010-06-23 14:35:10 -07:00
|
|
|
NOTHING,
|
2011-09-08 20:29:15 -07:00
|
|
|
Wrapper::enumerate(cx, wrapper, props),
|
2010-06-25 15:58:09 -07:00
|
|
|
call.origin->wrap(cx, props));
|
2010-06-23 14:35:10 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2011-09-08 20:29:15 -07:00
|
|
|
CrossCompartmentWrapper::has(JSContext *cx, JSObject *wrapper, jsid id, bool *bp)
|
2010-06-23 14:35:10 -07:00
|
|
|
{
|
2010-07-02 13:54:53 -07:00
|
|
|
PIERCE(cx, wrapper, GET,
|
2010-06-23 14:35:10 -07:00
|
|
|
call.destination->wrapId(cx, &id),
|
2011-09-08 20:29:15 -07:00
|
|
|
Wrapper::has(cx, wrapper, id, bp),
|
2010-06-23 14:35:10 -07:00
|
|
|
NOTHING);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2011-09-08 20:29:15 -07:00
|
|
|
CrossCompartmentWrapper::hasOwn(JSContext *cx, JSObject *wrapper, jsid id, bool *bp)
|
2010-06-23 14:35:10 -07:00
|
|
|
{
|
2010-07-02 13:54:53 -07:00
|
|
|
PIERCE(cx, wrapper, GET,
|
2010-06-23 14:35:10 -07:00
|
|
|
call.destination->wrapId(cx, &id),
|
2011-09-08 20:29:15 -07:00
|
|
|
Wrapper::hasOwn(cx, wrapper, id, bp),
|
2010-06-23 14:35:10 -07:00
|
|
|
NOTHING);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2011-09-08 20:29:15 -07:00
|
|
|
CrossCompartmentWrapper::get(JSContext *cx, JSObject *wrapper, JSObject *receiver, jsid id, Value *vp)
|
2010-06-23 14:35:10 -07:00
|
|
|
{
|
2010-07-02 13:54:53 -07:00
|
|
|
PIERCE(cx, wrapper, GET,
|
2010-06-23 14:35:10 -07:00
|
|
|
call.destination->wrap(cx, &receiver) && call.destination->wrapId(cx, &id),
|
2011-09-08 20:29:15 -07:00
|
|
|
Wrapper::get(cx, wrapper, receiver, id, vp),
|
2010-06-23 14:35:10 -07:00
|
|
|
call.origin->wrap(cx, vp));
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2012-04-30 17:10:30 -07:00
|
|
|
CrossCompartmentWrapper::set(JSContext *cx, JSObject *wrapper_, JSObject *receiver_, jsid id_,
|
2011-09-08 20:29:15 -07:00
|
|
|
bool strict, Value *vp)
|
2010-06-23 14:35:10 -07:00
|
|
|
{
|
2012-04-30 17:10:30 -07:00
|
|
|
RootedVarObject wrapper(cx, wrapper_), receiver(cx, receiver_);
|
|
|
|
RootedVarId id(cx, id_);
|
|
|
|
RootedVarValue value(cx, *vp);
|
2010-07-02 13:54:53 -07:00
|
|
|
PIERCE(cx, wrapper, SET,
|
2012-04-30 17:10:30 -07:00
|
|
|
call.destination->wrap(cx, receiver.address()) &&
|
|
|
|
call.destination->wrapId(cx, id.address()) &&
|
|
|
|
call.destination->wrap(cx, value.address()),
|
|
|
|
Wrapper::set(cx, wrapper, receiver, id, strict, value.address()),
|
2010-06-23 14:35:10 -07:00
|
|
|
NOTHING);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2011-09-08 20:29:15 -07:00
|
|
|
CrossCompartmentWrapper::keys(JSContext *cx, JSObject *wrapper, AutoIdVector &props)
|
2010-06-23 14:35:10 -07:00
|
|
|
{
|
2010-07-02 13:54:53 -07:00
|
|
|
PIERCE(cx, wrapper, GET,
|
2010-06-23 14:35:10 -07:00
|
|
|
NOTHING,
|
2011-09-08 20:29:15 -07:00
|
|
|
Wrapper::keys(cx, wrapper, props),
|
2010-06-25 15:58:09 -07:00
|
|
|
call.origin->wrap(cx, props));
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We can reify non-escaping iterator objects instead of having to wrap them. This
|
|
|
|
* allows fast iteration over objects across a compartment boundary.
|
|
|
|
*/
|
|
|
|
static bool
|
2010-07-14 23:19:36 -07:00
|
|
|
CanReify(Value *vp)
|
2010-06-25 15:58:09 -07:00
|
|
|
{
|
2010-07-14 23:19:36 -07:00
|
|
|
JSObject *obj;
|
|
|
|
return vp->isObject() &&
|
2011-09-02 17:23:26 -07:00
|
|
|
(obj = &vp->toObject())->getClass() == &IteratorClass &&
|
2010-07-14 23:19:36 -07:00
|
|
|
(obj->getNativeIterator()->flags & JSITER_ENUMERATE);
|
2010-06-25 15:58:09 -07:00
|
|
|
}
|
|
|
|
|
2010-12-14 06:34:46 -08:00
|
|
|
struct AutoCloseIterator
|
|
|
|
{
|
|
|
|
AutoCloseIterator(JSContext *cx, JSObject *obj) : cx(cx), obj(obj) {}
|
|
|
|
|
2012-02-27 17:01:52 -08:00
|
|
|
~AutoCloseIterator() { if (obj) CloseIterator(cx, obj); }
|
2010-12-14 06:34:46 -08:00
|
|
|
|
|
|
|
void clear() { obj = NULL; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
JSContext *cx;
|
|
|
|
JSObject *obj;
|
|
|
|
};
|
|
|
|
|
2010-06-25 15:58:09 -07:00
|
|
|
static bool
|
2010-07-14 23:19:36 -07:00
|
|
|
Reify(JSContext *cx, JSCompartment *origin, Value *vp)
|
2010-06-25 15:58:09 -07:00
|
|
|
{
|
2010-07-14 23:19:36 -07:00
|
|
|
JSObject *iterObj = &vp->toObject();
|
2010-06-25 15:58:09 -07:00
|
|
|
NativeIterator *ni = iterObj->getNativeIterator();
|
2010-07-14 23:19:36 -07:00
|
|
|
|
2010-12-14 06:34:46 -08:00
|
|
|
AutoCloseIterator close(cx, iterObj);
|
|
|
|
|
2010-07-14 23:19:36 -07:00
|
|
|
/* Wrap the iteratee. */
|
2012-04-12 09:23:51 -07:00
|
|
|
RootedVarObject obj(cx, ni->obj);
|
|
|
|
if (!origin->wrap(cx, obj.address()))
|
2010-07-14 23:19:36 -07:00
|
|
|
return false;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Wrap the elements in the iterator's snapshot.
|
|
|
|
* N.B. the order of closing/creating iterators is important due to the
|
|
|
|
* implicit cx->enumerators state.
|
|
|
|
*/
|
2011-01-14 17:15:21 -08:00
|
|
|
size_t length = ni->numKeys();
|
|
|
|
bool isKeyIter = ni->isKeyIter();
|
|
|
|
AutoIdVector keys(cx);
|
2010-06-25 15:58:09 -07:00
|
|
|
if (length > 0) {
|
2012-03-26 11:06:49 -07:00
|
|
|
if (!keys.reserve(length))
|
2010-07-14 23:19:36 -07:00
|
|
|
return false;
|
|
|
|
for (size_t i = 0; i < length; ++i) {
|
2012-01-18 16:56:22 -08:00
|
|
|
jsid id;
|
|
|
|
if (!ValueToId(cx, StringValue(ni->begin()[i]), &id))
|
|
|
|
return false;
|
2012-03-26 11:06:49 -07:00
|
|
|
keys.infallibleAppend(id);
|
2011-01-14 17:15:21 -08:00
|
|
|
if (!origin->wrapId(cx, &keys[i]))
|
2010-07-14 23:19:36 -07:00
|
|
|
return false;
|
|
|
|
}
|
2010-06-25 15:58:09 -07:00
|
|
|
}
|
|
|
|
|
2010-12-14 06:34:46 -08:00
|
|
|
close.clear();
|
2012-02-27 17:01:52 -08:00
|
|
|
if (!CloseIterator(cx, iterObj))
|
2011-01-14 17:15:21 -08:00
|
|
|
return false;
|
|
|
|
|
|
|
|
if (isKeyIter)
|
|
|
|
return VectorToKeyIterator(cx, obj, ni->flags, keys, vp);
|
|
|
|
return VectorToValueIterator(cx, obj, ni->flags, keys, vp);
|
2010-06-23 14:35:10 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2012-02-28 15:11:11 -08:00
|
|
|
CrossCompartmentWrapper::iterate(JSContext *cx, JSObject *wrapper, unsigned flags, Value *vp)
|
2010-06-23 14:35:10 -07:00
|
|
|
{
|
2010-07-02 13:54:53 -07:00
|
|
|
PIERCE(cx, wrapper, GET,
|
2010-06-23 14:35:10 -07:00
|
|
|
NOTHING,
|
2011-09-08 20:29:15 -07:00
|
|
|
Wrapper::iterate(cx, wrapper, flags, vp),
|
2010-06-25 15:58:09 -07:00
|
|
|
CanReify(vp) ? Reify(cx, call.origin, vp) : call.origin->wrap(cx, vp));
|
2010-06-23 14:35:10 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2012-04-30 17:10:30 -07:00
|
|
|
CrossCompartmentWrapper::call(JSContext *cx, JSObject *wrapper_, unsigned argc, Value *vp)
|
2010-06-23 14:35:10 -07:00
|
|
|
{
|
2012-04-30 17:10:30 -07:00
|
|
|
RootedVarObject wrapper(cx, wrapper_);
|
|
|
|
|
2010-07-02 13:54:53 -07:00
|
|
|
AutoCompartment call(cx, wrappedObject(wrapper));
|
2010-06-23 14:35:10 -07:00
|
|
|
if (!call.enter())
|
|
|
|
return false;
|
|
|
|
|
2010-07-14 23:19:36 -07:00
|
|
|
vp[0] = ObjectValue(*call.target);
|
2010-06-23 14:35:10 -07:00
|
|
|
if (!call.destination->wrap(cx, &vp[1]))
|
|
|
|
return false;
|
2010-07-14 23:19:36 -07:00
|
|
|
Value *argv = JS_ARGV(cx, vp);
|
2010-06-23 14:35:10 -07:00
|
|
|
for (size_t n = 0; n < argc; ++n) {
|
|
|
|
if (!call.destination->wrap(cx, &argv[n]))
|
|
|
|
return false;
|
|
|
|
}
|
2011-09-08 20:29:15 -07:00
|
|
|
if (!Wrapper::call(cx, wrapper, argc, vp))
|
2010-06-23 14:35:10 -07:00
|
|
|
return false;
|
|
|
|
|
|
|
|
call.leave();
|
|
|
|
return call.origin->wrap(cx, vp);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2012-04-30 17:10:30 -07:00
|
|
|
CrossCompartmentWrapper::construct(JSContext *cx, JSObject *wrapper_, unsigned argc, Value *argv,
|
2011-09-08 20:29:15 -07:00
|
|
|
Value *rval)
|
2010-06-23 14:35:10 -07:00
|
|
|
{
|
2012-04-30 17:10:30 -07:00
|
|
|
RootedVarObject wrapper(cx, wrapper_);
|
|
|
|
|
2010-07-02 13:54:53 -07:00
|
|
|
AutoCompartment call(cx, wrappedObject(wrapper));
|
2010-06-23 14:35:10 -07:00
|
|
|
if (!call.enter())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
for (size_t n = 0; n < argc; ++n) {
|
|
|
|
if (!call.destination->wrap(cx, &argv[n]))
|
|
|
|
return false;
|
|
|
|
}
|
2011-09-08 20:29:15 -07:00
|
|
|
if (!Wrapper::construct(cx, wrapper, argc, argv, rval))
|
2010-06-23 14:35:10 -07:00
|
|
|
return false;
|
|
|
|
|
|
|
|
call.leave();
|
2011-01-07 09:13:00 -08:00
|
|
|
return call.origin->wrap(cx, rval);
|
2010-06-23 14:35:10 -07:00
|
|
|
}
|
|
|
|
|
2011-10-07 11:58:47 -07:00
|
|
|
extern JSBool
|
2012-02-28 15:11:11 -08:00
|
|
|
js_generic_native_method_dispatcher(JSContext *cx, unsigned argc, Value *vp);
|
2011-10-07 11:58:47 -07:00
|
|
|
|
2011-09-08 21:06:41 -07:00
|
|
|
bool
|
|
|
|
CrossCompartmentWrapper::nativeCall(JSContext *cx, JSObject *wrapper, Class *clasp, Native native, CallArgs srcArgs)
|
|
|
|
{
|
2011-09-20 16:48:50 -07:00
|
|
|
JS_ASSERT_IF(!srcArgs.calleev().isUndefined(),
|
2011-10-19 14:26:08 -07:00
|
|
|
srcArgs.callee().toFunction()->native() == native ||
|
|
|
|
srcArgs.callee().toFunction()->native() == js_generic_native_method_dispatcher);
|
2011-09-08 21:06:41 -07:00
|
|
|
JS_ASSERT(&srcArgs.thisv().toObject() == wrapper);
|
2011-10-04 10:48:36 -07:00
|
|
|
JS_ASSERT(!UnwrapObject(wrapper)->isCrossCompartmentWrapper());
|
2011-09-08 21:06:41 -07:00
|
|
|
|
|
|
|
JSObject *wrapped = wrappedObject(wrapper);
|
|
|
|
AutoCompartment call(cx, wrapped);
|
|
|
|
if (!call.enter())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
InvokeArgsGuard dstArgs;
|
|
|
|
if (!cx->stack.pushInvokeArgs(cx, srcArgs.length(), &dstArgs))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
Value *src = srcArgs.base();
|
|
|
|
Value *srcend = srcArgs.array() + srcArgs.length();
|
|
|
|
Value *dst = dstArgs.base();
|
|
|
|
for (; src != srcend; ++src, ++dst) {
|
|
|
|
*dst = *src;
|
|
|
|
if (!call.destination->wrap(cx, dst))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!Wrapper::nativeCall(cx, wrapper, clasp, native, dstArgs))
|
|
|
|
return false;
|
|
|
|
|
2012-02-22 10:36:12 -08:00
|
|
|
srcArgs.rval() = dstArgs.rval();
|
2011-09-08 21:06:41 -07:00
|
|
|
dstArgs.pop();
|
|
|
|
call.leave();
|
|
|
|
return call.origin->wrap(cx, &srcArgs.rval());
|
|
|
|
}
|
|
|
|
|
2010-10-10 15:39:26 -07:00
|
|
|
bool
|
2011-09-08 20:29:15 -07:00
|
|
|
CrossCompartmentWrapper::hasInstance(JSContext *cx, JSObject *wrapper, const Value *vp, bool *bp)
|
2010-10-10 15:39:26 -07:00
|
|
|
{
|
|
|
|
AutoCompartment call(cx, wrappedObject(wrapper));
|
|
|
|
if (!call.enter())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
Value v = *vp;
|
|
|
|
if (!call.destination->wrap(cx, &v))
|
|
|
|
return false;
|
2011-09-08 20:29:15 -07:00
|
|
|
return Wrapper::hasInstance(cx, wrapper, &v, bp);
|
2010-10-10 15:39:26 -07:00
|
|
|
}
|
|
|
|
|
2010-06-23 14:35:10 -07:00
|
|
|
JSString *
|
2011-09-08 20:29:15 -07:00
|
|
|
CrossCompartmentWrapper::obj_toString(JSContext *cx, JSObject *wrapper)
|
2010-06-23 14:35:10 -07:00
|
|
|
{
|
2010-07-02 13:54:53 -07:00
|
|
|
AutoCompartment call(cx, wrappedObject(wrapper));
|
2010-06-23 14:35:10 -07:00
|
|
|
if (!call.enter())
|
|
|
|
return NULL;
|
|
|
|
|
2011-09-08 20:29:15 -07:00
|
|
|
JSString *str = Wrapper::obj_toString(cx, wrapper);
|
2010-06-23 14:35:10 -07:00
|
|
|
if (!str)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
call.leave();
|
|
|
|
if (!call.origin->wrap(cx, &str))
|
|
|
|
return NULL;
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
|
|
|
JSString *
|
2012-02-28 15:11:11 -08:00
|
|
|
CrossCompartmentWrapper::fun_toString(JSContext *cx, JSObject *wrapper, unsigned indent)
|
2010-06-23 14:35:10 -07:00
|
|
|
{
|
2010-07-02 13:54:53 -07:00
|
|
|
AutoCompartment call(cx, wrappedObject(wrapper));
|
2010-06-23 14:35:10 -07:00
|
|
|
if (!call.enter())
|
|
|
|
return NULL;
|
|
|
|
|
2011-09-08 20:29:15 -07:00
|
|
|
JSString *str = Wrapper::fun_toString(cx, wrapper, indent);
|
2010-06-23 14:35:10 -07:00
|
|
|
if (!str)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
call.leave();
|
|
|
|
if (!call.origin->wrap(cx, &str))
|
|
|
|
return NULL;
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
2011-04-01 15:24:21 -07:00
|
|
|
bool
|
2011-09-08 20:29:15 -07:00
|
|
|
CrossCompartmentWrapper::defaultValue(JSContext *cx, JSObject *wrapper, JSType hint, Value *vp)
|
2011-04-01 15:24:21 -07:00
|
|
|
{
|
|
|
|
AutoCompartment call(cx, wrappedObject(wrapper));
|
|
|
|
if (!call.enter())
|
|
|
|
return false;
|
|
|
|
|
2011-09-08 20:29:15 -07:00
|
|
|
if (!Wrapper::defaultValue(cx, wrapper, hint, vp))
|
2011-04-01 15:24:21 -07:00
|
|
|
return false;
|
|
|
|
|
|
|
|
call.leave();
|
|
|
|
return call.origin->wrap(cx, vp);
|
|
|
|
}
|
|
|
|
|
2012-02-07 10:57:16 -08:00
|
|
|
bool
|
|
|
|
CrossCompartmentWrapper::iteratorNext(JSContext *cx, JSObject *wrapper, Value *vp)
|
|
|
|
{
|
|
|
|
PIERCE(cx, wrapper, GET,
|
|
|
|
NOTHING,
|
|
|
|
Wrapper::iteratorNext(cx, wrapper, vp),
|
|
|
|
call.origin->wrap(cx, vp));
|
|
|
|
}
|
|
|
|
|
2011-07-07 17:31:24 -07:00
|
|
|
void
|
2011-09-08 20:29:15 -07:00
|
|
|
CrossCompartmentWrapper::trace(JSTracer *trc, JSObject *wrapper)
|
2011-07-07 17:31:24 -07:00
|
|
|
{
|
2012-02-17 18:43:48 -08:00
|
|
|
MarkCrossCompartmentSlot(trc, &wrapper->getReservedSlotRef(JSSLOT_PROXY_PRIVATE),
|
|
|
|
"wrappedObject");
|
2011-07-07 17:31:24 -07:00
|
|
|
}
|
|
|
|
|
2011-09-08 20:29:15 -07:00
|
|
|
CrossCompartmentWrapper CrossCompartmentWrapper::singleton(0u);
|
2011-10-04 10:50:25 -07:00
|
|
|
|
|
|
|
/* Security wrappers. */
|
|
|
|
|
|
|
|
template <class Base>
|
2012-02-28 15:11:11 -08:00
|
|
|
SecurityWrapper<Base>::SecurityWrapper(unsigned flags)
|
2011-10-04 10:50:25 -07:00
|
|
|
: Base(flags)
|
|
|
|
{}
|
|
|
|
|
|
|
|
template <class Base>
|
|
|
|
bool
|
|
|
|
SecurityWrapper<Base>::nativeCall(JSContext *cx, JSObject *wrapper, Class *clasp, Native native,
|
|
|
|
CallArgs args)
|
|
|
|
{
|
2012-01-09 15:32:53 -08:00
|
|
|
/*
|
|
|
|
* Let this through until compartment-per-global lets us have stronger
|
|
|
|
* invariants wrt document.domain (bug 714547).
|
|
|
|
*/
|
|
|
|
return Base::nativeCall(cx, wrapper, clasp, native, args);
|
2011-10-04 10:50:25 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
template <class Base>
|
|
|
|
bool
|
|
|
|
SecurityWrapper<Base>::objectClassIs(JSObject *obj, ESClassValue classValue, JSContext *cx)
|
|
|
|
{
|
2012-01-09 15:32:53 -08:00
|
|
|
/*
|
|
|
|
* Let this through until compartment-per-global lets us have stronger
|
|
|
|
* invariants wrt document.domain (bug 714547).
|
|
|
|
*/
|
|
|
|
return Base::objectClassIs(obj, classValue, cx);
|
2011-10-04 10:50:25 -07:00
|
|
|
}
|
|
|
|
|
2012-02-01 13:36:48 -08:00
|
|
|
template <class Base>
|
2012-02-23 13:51:19 -08:00
|
|
|
bool
|
|
|
|
SecurityWrapper<Base>::regexp_toShared(JSContext *cx, JSObject *obj, RegExpGuard *g)
|
2012-02-01 13:36:48 -08:00
|
|
|
{
|
2012-02-23 13:51:19 -08:00
|
|
|
return Base::regexp_toShared(cx, obj, g);
|
2012-02-01 13:36:48 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-10-26 02:50:40 -07:00
|
|
|
template class js::SecurityWrapper<Wrapper>;
|
|
|
|
template class js::SecurityWrapper<CrossCompartmentWrapper>;
|
2012-04-25 21:03:53 -07:00
|
|
|
|
|
|
|
class JS_FRIEND_API(DeadObjectProxy) : public ProxyHandler
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
static int sDeadObjectFamily;
|
|
|
|
public:
|
|
|
|
|
|
|
|
explicit DeadObjectProxy();
|
|
|
|
|
|
|
|
/* ES5 Harmony fundamental wrapper traps. */
|
|
|
|
virtual bool getPropertyDescriptor(JSContext *cx, JSObject *wrapper, jsid id, bool set,
|
|
|
|
PropertyDescriptor *desc) MOZ_OVERRIDE;
|
|
|
|
virtual bool getOwnPropertyDescriptor(JSContext *cx, JSObject *wrapper, jsid id, bool set,
|
|
|
|
PropertyDescriptor *desc) MOZ_OVERRIDE;
|
|
|
|
virtual bool defineProperty(JSContext *cx, JSObject *wrapper, jsid id,
|
|
|
|
PropertyDescriptor *desc) MOZ_OVERRIDE;
|
|
|
|
virtual bool getOwnPropertyNames(JSContext *cx, JSObject *wrapper, AutoIdVector &props) MOZ_OVERRIDE;
|
|
|
|
virtual bool delete_(JSContext *cx, JSObject *wrapper, jsid id, bool *bp) MOZ_OVERRIDE;
|
|
|
|
virtual bool enumerate(JSContext *cx, JSObject *wrapper, AutoIdVector &props) MOZ_OVERRIDE;
|
|
|
|
|
|
|
|
/* Spidermonkey extensions. */
|
|
|
|
virtual bool call(JSContext *cx, JSObject *proxy, unsigned argc, Value *vp);
|
|
|
|
virtual bool construct(JSContext *cx, JSObject *proxy, unsigned argc, Value *argv, Value *rval);
|
|
|
|
virtual bool nativeCall(JSContext *cx, JSObject *proxy, Class *clasp, Native native, CallArgs args);
|
|
|
|
virtual bool hasInstance(JSContext *cx, JSObject *proxy, const Value *vp, bool *bp);
|
|
|
|
virtual bool objectClassIs(JSObject *obj, ESClassValue classValue, JSContext *cx);
|
|
|
|
virtual JSString *obj_toString(JSContext *cx, JSObject *proxy);
|
|
|
|
virtual JSString *fun_toString(JSContext *cx, JSObject *proxy, unsigned indent);
|
|
|
|
virtual bool regexp_toShared(JSContext *cx, JSObject *proxy, RegExpGuard *g);
|
|
|
|
virtual bool defaultValue(JSContext *cx, JSObject *obj, JSType hint, Value *vp);
|
|
|
|
virtual bool iteratorNext(JSContext *cx, JSObject *proxy, Value *vp);
|
|
|
|
virtual bool getElementIfPresent(JSContext *cx, JSObject *obj, JSObject *receiver,
|
|
|
|
uint32_t index, Value *vp, bool *present);
|
|
|
|
|
|
|
|
|
|
|
|
static DeadObjectProxy singleton;
|
|
|
|
};
|
|
|
|
|
|
|
|
DeadObjectProxy::DeadObjectProxy()
|
|
|
|
: ProxyHandler(&sDeadObjectFamily)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
DeadObjectProxy::getPropertyDescriptor(JSContext *cx, JSObject *wrapper,
|
|
|
|
jsid id, bool set,
|
|
|
|
PropertyDescriptor *desc)
|
|
|
|
{
|
|
|
|
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_DEAD_OBJECT);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
DeadObjectProxy::getOwnPropertyDescriptor(JSContext *cx, JSObject *wrapper,
|
|
|
|
jsid id, bool set,
|
|
|
|
PropertyDescriptor *desc)
|
|
|
|
{
|
|
|
|
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_DEAD_OBJECT);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
DeadObjectProxy::defineProperty(JSContext *cx, JSObject *wrapper, jsid id,
|
|
|
|
PropertyDescriptor *desc)
|
|
|
|
{
|
|
|
|
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_DEAD_OBJECT);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
DeadObjectProxy::getOwnPropertyNames(JSContext *cx, JSObject *wrapper,
|
|
|
|
AutoIdVector &props)
|
|
|
|
{
|
|
|
|
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_DEAD_OBJECT);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
DeadObjectProxy::delete_(JSContext *cx, JSObject *wrapper, jsid id, bool *bp)
|
|
|
|
{
|
|
|
|
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_DEAD_OBJECT);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
DeadObjectProxy::enumerate(JSContext *cx, JSObject *wrapper,
|
|
|
|
AutoIdVector &props)
|
|
|
|
{
|
|
|
|
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_DEAD_OBJECT);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
DeadObjectProxy::call(JSContext *cx, JSObject *wrapper, unsigned argc, Value *vp)
|
|
|
|
{
|
|
|
|
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_DEAD_OBJECT);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
DeadObjectProxy::construct(JSContext *cx, JSObject *wrapper, unsigned argc,
|
|
|
|
Value *vp, Value *rval)
|
|
|
|
{
|
|
|
|
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_DEAD_OBJECT);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
DeadObjectProxy::nativeCall(JSContext *cx, JSObject *wrapper, Class *clasp,
|
|
|
|
Native native, CallArgs args)
|
|
|
|
{
|
|
|
|
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_DEAD_OBJECT);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
DeadObjectProxy::hasInstance(JSContext *cx, JSObject *proxy, const Value *vp,
|
|
|
|
bool *bp)
|
|
|
|
{
|
|
|
|
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_DEAD_OBJECT);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
DeadObjectProxy::objectClassIs(JSObject *obj, ESClassValue classValue, JSContext *cx)
|
|
|
|
{
|
|
|
|
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_DEAD_OBJECT);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
JSString *
|
|
|
|
DeadObjectProxy::obj_toString(JSContext *cx, JSObject *wrapper)
|
|
|
|
{
|
|
|
|
return JS_NewStringCopyZ(cx, "[object DeadObject]");
|
|
|
|
}
|
|
|
|
|
|
|
|
JSString *
|
|
|
|
DeadObjectProxy::fun_toString(JSContext *cx, JSObject *proxy, unsigned indent)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
DeadObjectProxy::regexp_toShared(JSContext *cx, JSObject *proxy, RegExpGuard *g)
|
|
|
|
{
|
|
|
|
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_DEAD_OBJECT);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
DeadObjectProxy::defaultValue(JSContext *cx, JSObject *obj, JSType hint, Value *vp)
|
|
|
|
{
|
|
|
|
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_DEAD_OBJECT);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
DeadObjectProxy::iteratorNext(JSContext *cx, JSObject *proxy, Value *vp)
|
|
|
|
{
|
|
|
|
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_DEAD_OBJECT);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
DeadObjectProxy::getElementIfPresent(JSContext *cx, JSObject *obj, JSObject *receiver,
|
|
|
|
uint32_t index, Value *vp, bool *present)
|
|
|
|
{
|
|
|
|
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_DEAD_OBJECT);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
DeadObjectProxy DeadObjectProxy::singleton;
|
|
|
|
int DeadObjectProxy::sDeadObjectFamily;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* NukeChromeCrossCompartmentWrappersForGlobal reaches into chrome and cuts
|
|
|
|
* all of the cross-compartment wrappers that point to objects parented to
|
|
|
|
* obj's global. The snag here is that we need to avoid cutting wrappers that
|
|
|
|
* point to the window object on page navigation (inner window destruction)
|
|
|
|
* and only do that on tab close (outer window destruction). Thus the
|
|
|
|
* option of how to handle the global object.
|
|
|
|
*/
|
|
|
|
JS_FRIEND_API(JSBool)
|
|
|
|
js::NukeChromeCrossCompartmentWrappersForGlobal(JSContext *cx, JSObject *obj,
|
|
|
|
js::NukedGlobalHandling nukeGlobal)
|
|
|
|
{
|
|
|
|
CHECK_REQUEST(cx);
|
|
|
|
|
|
|
|
JSRuntime *rt = cx->runtime;
|
|
|
|
JSObject *global = &obj->global();
|
|
|
|
|
|
|
|
// Iterate through scopes looking for system cross compartment wrappers
|
|
|
|
// that point to an object that shares a global with obj.
|
|
|
|
|
|
|
|
for (CompartmentsIter c(rt); !c.done(); c.next()) {
|
|
|
|
// Skip non-system compartments because this breaks the web.
|
|
|
|
if (!js::IsSystemCompartment(c))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// Iterate the wrappers looking for anything interesting.
|
|
|
|
WrapperMap &pmap = c->crossCompartmentWrappers;
|
|
|
|
for (WrapperMap::Enum e(pmap); !e.empty(); e.popFront()) {
|
|
|
|
// Some cross-compartment wrappers are for strings. We're not
|
|
|
|
// interested in those.
|
|
|
|
const Value &k = e.front().key;
|
|
|
|
if (k.isString())
|
|
|
|
continue;
|
|
|
|
|
|
|
|
JSObject *wobj = &e.front().value.get().toObject();
|
|
|
|
JSObject *wrapped = UnwrapObject(wobj, false);
|
|
|
|
|
2012-05-03 00:10:08 -07:00
|
|
|
if (js::IsSystemCompartment(wrapped->compartment()))
|
|
|
|
continue; // Not interested in chrome->chrome wrappers.
|
|
|
|
|
2012-04-25 21:03:53 -07:00
|
|
|
if (nukeGlobal == DontNukeForGlobalObject && wrapped == global)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (&wrapped->global() == global) {
|
|
|
|
// We found a wrapper to nuke.
|
|
|
|
e.removeFront();
|
|
|
|
|
|
|
|
SetProxyPrivate(wobj, JSVAL_NULL);
|
|
|
|
SetProxyHandler(wobj, &DeadObjectProxy::singleton);
|
|
|
|
|
|
|
|
if (IsFunctionProxy(wobj)) {
|
|
|
|
wobj->setReservedSlot(JSSLOT_PROXY_CALL, JSVAL_NULL);
|
|
|
|
wobj->setReservedSlot(JSSLOT_PROXY_CONSTRUCT, JSVAL_NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
wobj->setReservedSlot(JSSLOT_PROXY_EXTRA + 0, JSVAL_NULL);
|
|
|
|
wobj->setReservedSlot(JSSLOT_PROXY_EXTRA + 1, JSVAL_NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return JS_TRUE;
|
|
|
|
}
|