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"
|
2011-07-13 04:46:23 -07:00
|
|
|
#include "jsexn.h"
|
2011-04-15 16:56:08 -07:00
|
|
|
#include "jsgc.h"
|
|
|
|
#include "jsgcmark.h"
|
2010-06-03 15:27:29 -07:00
|
|
|
#include "jsiter.h"
|
|
|
|
#include "jsnum.h"
|
2010-06-24 17:09:46 -07:00
|
|
|
#include "jsregexp.h"
|
2010-06-03 15:27:29 -07:00
|
|
|
#include "jswrapper.h"
|
2010-08-05 17:15:49 -07:00
|
|
|
#include "methodjit/PolyIC.h"
|
2010-08-12 16:58:43 -07:00
|
|
|
#include "methodjit/MonoIC.h"
|
2010-08-05 17:15:49 -07:00
|
|
|
#ifdef JS_METHODJIT
|
|
|
|
# include "assembler/jit/ExecutableAllocator.h"
|
|
|
|
#endif
|
2010-09-24 10:54:39 -07:00
|
|
|
#include "jscompartment.h"
|
2010-06-03 15:27:29 -07:00
|
|
|
|
|
|
|
#include "jsobjinlines.h"
|
|
|
|
|
|
|
|
using namespace js;
|
2010-09-24 10:54:39 -07:00
|
|
|
using namespace js::gc;
|
2010-06-03 15:27:29 -07:00
|
|
|
|
2010-09-20 14:48:01 -07:00
|
|
|
static int sWrapperFamily;
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
bool
|
|
|
|
JSObject::isWrapper() const
|
|
|
|
{
|
|
|
|
return isProxy() && getProxyHandler()->family() == &sWrapperFamily;
|
|
|
|
}
|
|
|
|
|
2011-05-20 22:40:33 -07:00
|
|
|
bool
|
|
|
|
JSObject::isCrossCompartmentWrapper() const
|
|
|
|
{
|
2011-09-08 20:29:15 -07:00
|
|
|
return isWrapper() && !!(getWrapperHandler()->flags() & Wrapper::CROSS_COMPARTMENT);
|
2011-05-20 22:40:33 -07:00
|
|
|
}
|
|
|
|
|
2011-09-08 20:29:15 -07:00
|
|
|
Wrapper *
|
2011-04-14 22:03:31 -07:00
|
|
|
JSObject::getWrapperHandler() const
|
|
|
|
{
|
|
|
|
JS_ASSERT(isWrapper());
|
2011-09-08 20:29:15 -07:00
|
|
|
return static_cast<Wrapper *>(getProxyHandler());
|
2011-04-14 22:03:31 -07:00
|
|
|
}
|
|
|
|
|
2010-06-24 14:45:32 -07:00
|
|
|
JSObject *
|
2010-07-02 13:54:53 -07:00
|
|
|
JSObject::unwrap(uintN *flagsp)
|
2010-06-24 14:45:32 -07:00
|
|
|
{
|
|
|
|
JSObject *wrapped = this;
|
2010-07-02 13:54:53 -07:00
|
|
|
uintN flags = 0;
|
2010-10-10 15:47:22 -07:00
|
|
|
while (wrapped->isWrapper()) {
|
2011-09-08 20:29:15 -07:00
|
|
|
flags |= static_cast<Wrapper *>(wrapped->getProxyHandler())->flags();
|
2010-07-14 23:19:36 -07:00
|
|
|
wrapped = wrapped->getProxyPrivate().toObjectOrNull();
|
2010-10-10 15:48:35 -07:00
|
|
|
if (wrapped->getClass()->ext.innerObject)
|
|
|
|
break;
|
2010-07-02 13:54:53 -07:00
|
|
|
}
|
|
|
|
if (flagsp)
|
|
|
|
*flagsp = flags;
|
2010-06-24 14:45:32 -07:00
|
|
|
return wrapped;
|
|
|
|
}
|
|
|
|
|
2011-09-08 20:29:15 -07:00
|
|
|
Wrapper::Wrapper(uintN flags) : ProxyHandler(&sWrapperFamily), mFlags(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
|
2011-09-08 20:29:15 -07:00
|
|
|
Wrapper::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
|
|
|
|
GetOwnPropertyDescriptor(JSContext *cx, JSObject *obj, jsid id, uintN flags, JSPropertyDescriptor *desc)
|
|
|
|
{
|
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
|
2011-09-08 20:29:15 -07:00
|
|
|
Wrapper::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
|
2011-09-08 20:29:15 -07:00
|
|
|
Wrapper::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
|
2011-09-08 20:29:15 -07:00
|
|
|
Wrapper::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
|
2011-09-08 20:29:15 -07:00
|
|
|
Wrapper::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
|
2011-09-08 20:29:15 -07:00
|
|
|
Wrapper::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
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2011-09-08 20:29:15 -07:00
|
|
|
Wrapper::fix(JSContext *cx, JSObject *wrapper, Value *vp)
|
2010-06-03 15:27:29 -07:00
|
|
|
{
|
2010-07-14 23:19:36 -07:00
|
|
|
vp->setUndefined();
|
2010-06-03 15:27:29 -07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2010-10-29 10:42:35 -07:00
|
|
|
// FIXME (bug 596351): Need deal with strict mode.
|
|
|
|
SET(wrappedObject(wrapper)->setProperty(cx, id, vp, false));
|
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
|
2011-09-08 20:29:15 -07:00
|
|
|
Wrapper::iterate(JSContext *cx, JSObject *wrapper, uintN 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;
|
2010-07-02 13:54:53 -07:00
|
|
|
GET(GetIterator(cx, wrappedObject(wrapper), flags, vp));
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2011-09-08 20:29:15 -07:00
|
|
|
Wrapper::call(JSContext *cx, JSObject *wrapper, uintN 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
|
2011-09-08 20:29:15 -07:00
|
|
|
Wrapper::construct(JSContext *cx, JSObject *wrapper, uintN 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
|
|
|
}
|
|
|
|
|
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)));
|
|
|
|
}
|
|
|
|
|
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 *
|
2011-09-08 20:29:15 -07:00
|
|
|
Wrapper::fun_toString(JSContext *cx, JSObject *wrapper, uintN 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
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2010-09-24 10:54:39 -07:00
|
|
|
MarkObject(trc, *wrappedObject(wrapper), "wrappedObject");
|
2010-06-03 15:27:29 -07:00
|
|
|
}
|
|
|
|
|
2011-04-08 19:51:40 -07:00
|
|
|
JSObject *
|
2011-09-08 20:29:15 -07:00
|
|
|
Wrapper::wrappedObject(const JSObject *wrapper)
|
2011-04-08 19:51:40 -07:00
|
|
|
{
|
|
|
|
return wrapper->getProxyPrivate().toObjectOrNull();
|
|
|
|
}
|
|
|
|
|
2011-09-08 20:29:15 -07:00
|
|
|
Wrapper *
|
|
|
|
Wrapper::wrapperHandler(const JSObject *wrapper)
|
2011-04-08 19:51:40 -07:00
|
|
|
{
|
2011-09-08 20:29:15 -07:00
|
|
|
return static_cast<Wrapper *>(wrapper->getProxyHandler());
|
2011-04-08 19:51:40 -07:00
|
|
|
}
|
|
|
|
|
2010-07-02 13:54:53 -07:00
|
|
|
bool
|
2011-09-08 20:29:15 -07:00
|
|
|
Wrapper::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
|
2011-09-08 20:29:15 -07:00
|
|
|
Wrapper::leave(JSContext *cx, JSObject *wrapper)
|
2010-07-02 13:54:53 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2011-09-08 20:29:15 -07:00
|
|
|
Wrapper Wrapper::singleton((uintN)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);
|
2010-11-10 15:56:00 -08:00
|
|
|
if (obj->isXML()) {
|
|
|
|
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_CANT_WRAP_XML_OBJECT);
|
|
|
|
return NULL;
|
|
|
|
}
|
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,
|
|
|
|
uintN 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
|
|
|
LeaveTrace(context);
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
JSObject *scopeChain = target->getGlobal();
|
|
|
|
JS_ASSERT(scopeChain->isNative());
|
|
|
|
|
2011-08-05 14:06:33 -07: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),
|
2010-09-27 13:49:09 -07:00
|
|
|
destination(target->getCompartment()),
|
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) {
|
2010-08-21 16:03:07 -07:00
|
|
|
LeaveTrace(context);
|
2010-09-27 18:24:24 -07:00
|
|
|
|
2010-08-21 16:03:07 -07:00
|
|
|
JSObject *scopeChain = target->getGlobal();
|
2010-11-01 18:28:14 -07:00
|
|
|
JS_ASSERT(scopeChain->isNative());
|
2011-01-07 09:13:00 -08:00
|
|
|
|
2010-07-20 16:59:29 -07:00
|
|
|
frame.construct();
|
2011-08-05 14:06:33 -07: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();
|
|
|
|
JSObject *copyobj = js_CopyErrorObject(cx, &exc.toObject(), scope);
|
|
|
|
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
|
|
|
|
2011-09-08 20:29:15 -07:00
|
|
|
CrossCompartmentWrapper::CrossCompartmentWrapper(uintN flags)
|
|
|
|
: 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
|
2011-09-08 20:29:15 -07:00
|
|
|
CrossCompartmentWrapper::set(JSContext *cx, JSObject *wrapper, JSObject *receiver, jsid id,
|
|
|
|
bool strict, Value *vp)
|
2010-06-23 14:35:10 -07:00
|
|
|
{
|
|
|
|
AutoValueRooter tvr(cx, *vp);
|
2010-07-02 13:54:53 -07:00
|
|
|
PIERCE(cx, wrapper, SET,
|
2011-02-09 11:31:40 -08:00
|
|
|
call.destination->wrap(cx, &receiver) &&
|
|
|
|
call.destination->wrapId(cx, &id) &&
|
|
|
|
call.destination->wrap(cx, tvr.addr()),
|
2011-09-08 20:29:15 -07:00
|
|
|
Wrapper::set(cx, wrapper, receiver, id, strict, tvr.addr()),
|
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) {}
|
|
|
|
|
|
|
|
~AutoCloseIterator() { if (obj) js_CloseIterator(cx, obj); }
|
|
|
|
|
|
|
|
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. */
|
|
|
|
JSObject *obj = ni->obj;
|
|
|
|
if (!origin->wrap(cx, &obj))
|
|
|
|
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) {
|
2011-01-14 17:15:21 -08:00
|
|
|
if (!keys.resize(length))
|
2010-07-14 23:19:36 -07:00
|
|
|
return false;
|
|
|
|
for (size_t i = 0; i < length; ++i) {
|
2011-01-14 17:15:21 -08:00
|
|
|
keys[i] = ni->begin()[i];
|
|
|
|
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();
|
2011-01-14 17:15:21 -08:00
|
|
|
if (!js_CloseIterator(cx, iterObj))
|
|
|
|
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
|
2011-09-08 20:29:15 -07:00
|
|
|
CrossCompartmentWrapper::iterate(JSContext *cx, JSObject *wrapper, uintN 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
|
2011-09-08 20:29:15 -07:00
|
|
|
CrossCompartmentWrapper::call(JSContext *cx, JSObject *wrapper, uintN argc, Value *vp)
|
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 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
|
2011-09-08 20:29:15 -07:00
|
|
|
CrossCompartmentWrapper::construct(JSContext *cx, JSObject *wrapper, uintN argc, Value *argv,
|
|
|
|
Value *rval)
|
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 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-09-08 21:06:41 -07:00
|
|
|
bool
|
|
|
|
CrossCompartmentWrapper::nativeCall(JSContext *cx, JSObject *wrapper, Class *clasp, Native native, CallArgs srcArgs)
|
|
|
|
{
|
|
|
|
JS_ASSERT(srcArgs.callee().getFunctionPrivate()->native() == native);
|
|
|
|
JS_ASSERT(&srcArgs.thisv().toObject() == wrapper);
|
|
|
|
JS_ASSERT(!wrapper->unwrap(NULL)->isProxy());
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
dstArgs.pop();
|
|
|
|
call.leave();
|
|
|
|
srcArgs.rval() = dstArgs.rval();
|
|
|
|
return call.origin->wrap(cx, &srcArgs.rval());
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
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 *
|
2011-09-08 20:29:15 -07:00
|
|
|
CrossCompartmentWrapper::fun_toString(JSContext *cx, JSObject *wrapper, uintN 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);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
|
|
|
MarkCrossCompartmentObject(trc, *wrappedObject(wrapper), "wrappedObject");
|
|
|
|
}
|
|
|
|
|
2011-09-08 20:29:15 -07:00
|
|
|
CrossCompartmentWrapper CrossCompartmentWrapper::singleton(0u);
|