2018-11-30 22:52:05 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
2018-11-30 18:39:55 +03:00
|
|
|
* vim: set ts=8 sts=2 et sw=2 tw=80:
|
2012-05-21 15:12:37 +04: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/. */
|
2010-06-04 02:27:29 +04:00
|
|
|
|
2018-02-21 19:30:19 +03:00
|
|
|
#ifndef js_Wrapper_h
|
|
|
|
#define js_Wrapper_h
|
2010-06-04 02:27:29 +04:00
|
|
|
|
2011-11-21 00:22:51 +04:00
|
|
|
#include "mozilla/Attributes.h"
|
2011-11-14 22:31:46 +04:00
|
|
|
|
2015-02-10 21:58:18 +03:00
|
|
|
#include "js/Proxy.h"
|
2010-06-04 02:27:29 +04:00
|
|
|
|
2011-09-09 07:29:15 +04:00
|
|
|
namespace js {
|
2010-09-26 07:05:36 +04:00
|
|
|
|
2014-01-30 05:20:16 +04:00
|
|
|
/*
|
|
|
|
* Helper for Wrapper::New default options.
|
|
|
|
*
|
|
|
|
* Callers of Wrapper::New() who wish to specify a prototype for the created
|
|
|
|
* Wrapper, *MUST* construct a WrapperOptions with a JSContext.
|
|
|
|
*/
|
|
|
|
class MOZ_STACK_CLASS WrapperOptions : public ProxyOptions {
|
|
|
|
public:
|
2014-09-11 02:52:36 +04:00
|
|
|
WrapperOptions() : ProxyOptions(false), proto_() {}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-03-29 01:22:11 +03:00
|
|
|
explicit WrapperOptions(JSContext* cx) : ProxyOptions(false), proto_() {
|
2014-08-14 02:42:00 +04:00
|
|
|
proto_.emplace(cx);
|
2014-01-30 05:20:16 +04:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-03-29 01:22:11 +03:00
|
|
|
inline JSObject* proto() const;
|
|
|
|
WrapperOptions& setProto(JSObject* protoArg) {
|
2014-10-01 21:17:51 +04:00
|
|
|
MOZ_ASSERT(proto_);
|
2014-08-14 02:42:00 +04:00
|
|
|
*proto_ = protoArg;
|
2014-01-30 05:20:16 +04:00
|
|
|
return *this;
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-01-30 05:20:16 +04:00
|
|
|
private:
|
|
|
|
mozilla::Maybe<JS::RootedObject> proto_;
|
|
|
|
};
|
|
|
|
|
2017-08-16 14:18:57 +03:00
|
|
|
// Base class for proxy handlers that want to forward all operations to an
|
|
|
|
// object stored in the proxy's private slot.
|
2018-11-19 20:02:47 +03:00
|
|
|
class JS_FRIEND_API ForwardingProxyHandler : public BaseProxyHandler {
|
2016-05-04 03:29:10 +03:00
|
|
|
public:
|
2017-08-16 14:18:57 +03:00
|
|
|
using BaseProxyHandler::BaseProxyHandler;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2016-05-04 03:29:10 +03:00
|
|
|
/* Standard internal methods. */
|
|
|
|
virtual bool getOwnPropertyDescriptor(
|
|
|
|
JSContext* cx, HandleObject proxy, HandleId id,
|
|
|
|
MutableHandle<PropertyDescriptor> desc) const override;
|
|
|
|
virtual bool defineProperty(JSContext* cx, HandleObject proxy, HandleId id,
|
|
|
|
Handle<PropertyDescriptor> desc,
|
|
|
|
ObjectOpResult& result) const override;
|
|
|
|
virtual bool ownPropertyKeys(JSContext* cx, HandleObject proxy,
|
|
|
|
AutoIdVector& props) const override;
|
|
|
|
virtual bool delete_(JSContext* cx, HandleObject proxy, HandleId id,
|
|
|
|
ObjectOpResult& result) const override;
|
2019-02-08 11:17:00 +03:00
|
|
|
virtual bool enumerate(JSContext* cx, HandleObject proxy,
|
|
|
|
AutoIdVector& props) const override;
|
2016-05-04 03:29:10 +03:00
|
|
|
virtual bool getPrototype(JSContext* cx, HandleObject proxy,
|
|
|
|
MutableHandleObject protop) const override;
|
|
|
|
virtual bool setPrototype(JSContext* cx, HandleObject proxy,
|
|
|
|
HandleObject proto,
|
|
|
|
ObjectOpResult& result) const override;
|
2016-02-24 00:42:30 +03:00
|
|
|
virtual bool getPrototypeIfOrdinary(
|
|
|
|
JSContext* cx, HandleObject proxy, bool* isOrdinary,
|
2016-05-04 03:29:10 +03:00
|
|
|
MutableHandleObject protop) const override;
|
|
|
|
virtual bool setImmutablePrototype(JSContext* cx, HandleObject proxy,
|
|
|
|
bool* succeeded) const override;
|
|
|
|
virtual bool preventExtensions(JSContext* cx, HandleObject proxy,
|
|
|
|
ObjectOpResult& result) const override;
|
|
|
|
virtual bool isExtensible(JSContext* cx, HandleObject proxy,
|
|
|
|
bool* extensible) const override;
|
|
|
|
virtual bool has(JSContext* cx, HandleObject proxy, HandleId id,
|
|
|
|
bool* bp) const override;
|
|
|
|
virtual bool get(JSContext* cx, HandleObject proxy, HandleValue receiver,
|
|
|
|
HandleId id, MutableHandleValue vp) const override;
|
|
|
|
virtual bool set(JSContext* cx, HandleObject proxy, HandleId id,
|
|
|
|
HandleValue v, HandleValue receiver,
|
|
|
|
ObjectOpResult& result) const override;
|
|
|
|
virtual bool call(JSContext* cx, HandleObject proxy,
|
|
|
|
const CallArgs& args) const override;
|
|
|
|
virtual bool construct(JSContext* cx, HandleObject proxy,
|
|
|
|
const CallArgs& args) const override;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2016-05-04 03:29:10 +03:00
|
|
|
/* SpiderMonkey extensions. */
|
|
|
|
virtual bool hasOwn(JSContext* cx, HandleObject proxy, HandleId id,
|
|
|
|
bool* bp) const override;
|
|
|
|
virtual bool getOwnEnumerablePropertyKeys(JSContext* cx, HandleObject proxy,
|
|
|
|
AutoIdVector& props) const override;
|
|
|
|
virtual bool nativeCall(JSContext* cx, IsAcceptableThis test, NativeImpl impl,
|
|
|
|
const CallArgs& args) const override;
|
|
|
|
virtual bool hasInstance(JSContext* cx, HandleObject proxy,
|
|
|
|
MutableHandleValue v, bool* bp) const override;
|
2016-06-30 01:04:56 +03:00
|
|
|
virtual bool getBuiltinClass(JSContext* cx, HandleObject proxy,
|
|
|
|
ESClass* cls) const override;
|
2016-05-04 03:29:10 +03:00
|
|
|
virtual bool isArray(JSContext* cx, HandleObject proxy,
|
|
|
|
JS::IsArrayAnswer* answer) const override;
|
|
|
|
virtual const char* className(JSContext* cx,
|
|
|
|
HandleObject proxy) const override;
|
|
|
|
virtual JSString* fun_toString(JSContext* cx, HandleObject proxy,
|
2017-07-25 14:22:11 +03:00
|
|
|
bool isToSource) const override;
|
2017-07-11 12:31:12 +03:00
|
|
|
virtual RegExpShared* regexp_toShared(JSContext* cx,
|
|
|
|
HandleObject proxy) const override;
|
2016-05-04 03:29:10 +03:00
|
|
|
virtual bool boxedValue_unbox(JSContext* cx, HandleObject proxy,
|
|
|
|
MutableHandleValue vp) const override;
|
|
|
|
virtual bool isCallable(JSObject* obj) const override;
|
|
|
|
virtual bool isConstructor(JSObject* obj) const override;
|
2017-08-16 14:18:57 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* A wrapper is a proxy with a target object to which it generally forwards
|
|
|
|
* operations, but may restrict access to certain operations or augment those
|
|
|
|
* operations in various ways.
|
|
|
|
*
|
|
|
|
* A wrapper can be "unwrapped" in C++, exposing the underlying object.
|
|
|
|
* Callers should be careful to avoid unwrapping security wrappers in the wrong
|
|
|
|
* context.
|
|
|
|
*
|
|
|
|
* Important: If you add a method implementation here, you probably also need
|
|
|
|
* to add an override in CrossCompartmentWrapper. If you don't, you risk
|
|
|
|
* compartment mismatches. See bug 945826 comment 0.
|
|
|
|
*/
|
2018-11-19 20:02:47 +03:00
|
|
|
class JS_FRIEND_API Wrapper : public ForwardingProxyHandler {
|
2017-08-16 14:18:57 +03:00
|
|
|
unsigned mFlags;
|
2016-05-04 03:29:10 +03:00
|
|
|
|
2010-07-02 05:06:33 +04:00
|
|
|
public:
|
2017-08-16 14:18:57 +03:00
|
|
|
explicit constexpr Wrapper(unsigned aFlags, bool aHasPrototype = false,
|
|
|
|
bool aHasSecurityPolicy = false)
|
|
|
|
: ForwardingProxyHandler(&family, aHasPrototype, aHasSecurityPolicy),
|
|
|
|
mFlags(aFlags) {}
|
|
|
|
|
|
|
|
virtual bool finalizeInBackground(const Value& priv) const override;
|
|
|
|
|
2019-02-02 06:22:29 +03:00
|
|
|
/**
|
|
|
|
* A hook subclasses can override to implement CheckedUnwrapDynamic
|
|
|
|
* behavior. The JSContext represents the "who is trying to unwrap?" Realm.
|
|
|
|
* The JSObject is the wrapper that the caller is trying to unwrap.
|
|
|
|
*/
|
|
|
|
virtual bool dynamicCheckedUnwrapAllowed(HandleObject obj,
|
|
|
|
JSContext* cx) const {
|
|
|
|
MOZ_ASSERT(hasSecurityPolicy(), "Why are you asking?");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-02-26 01:54:18 +04:00
|
|
|
using BaseProxyHandler::Action;
|
2012-04-19 22:19:41 +04:00
|
|
|
|
2012-06-28 06:10:37 +04:00
|
|
|
enum Flags { CROSS_COMPARTMENT = 1 << 0, LAST_USED_FLAG = CROSS_COMPARTMENT };
|
2010-06-04 02:27:29 +04:00
|
|
|
|
2015-03-29 01:22:11 +03:00
|
|
|
static JSObject* New(JSContext* cx, JSObject* obj, const Wrapper* handler,
|
|
|
|
const WrapperOptions& options = WrapperOptions());
|
2012-06-28 06:10:37 +04:00
|
|
|
|
2017-02-08 17:04:57 +03:00
|
|
|
static JSObject* Renew(JSObject* existing, JSObject* obj,
|
|
|
|
const Wrapper* handler);
|
2012-09-12 04:14:24 +04:00
|
|
|
|
2018-07-06 13:53:38 +03:00
|
|
|
static inline const Wrapper* wrapperHandler(const JSObject* wrapper);
|
2012-06-28 06:10:37 +04:00
|
|
|
|
2015-03-29 01:22:11 +03:00
|
|
|
static JSObject* wrappedObject(JSObject* wrapper);
|
2012-06-28 06:10:37 +04:00
|
|
|
|
|
|
|
unsigned flags() const { return mFlags; }
|
|
|
|
|
2018-12-14 14:00:48 +03:00
|
|
|
bool isCrossCompartmentWrapper() const {
|
|
|
|
return !!(mFlags & CROSS_COMPARTMENT);
|
|
|
|
}
|
|
|
|
|
2014-08-28 04:09:06 +04:00
|
|
|
static const char family;
|
2014-06-27 15:44:04 +04:00
|
|
|
static const Wrapper singleton;
|
|
|
|
static const Wrapper singletonWithPrototype;
|
2014-01-30 05:20:16 +04:00
|
|
|
|
2018-04-20 14:07:14 +03:00
|
|
|
static JSObject* const defaultProto;
|
2010-06-24 01:35:10 +04:00
|
|
|
};
|
|
|
|
|
2014-01-30 05:57:36 +04:00
|
|
|
inline JSObject* WrapperOptions::proto() const {
|
2014-08-14 02:42:00 +04:00
|
|
|
return proto_ ? *proto_ : Wrapper::defaultProto;
|
2014-01-30 05:57:36 +04:00
|
|
|
}
|
|
|
|
|
2010-06-25 01:45:32 +04:00
|
|
|
/* Base class for all cross compartment wrapper handlers. */
|
2018-11-19 20:02:47 +03:00
|
|
|
class JS_FRIEND_API CrossCompartmentWrapper : public Wrapper {
|
2010-06-25 01:45:32 +04:00
|
|
|
public:
|
2016-07-09 00:39:53 +03:00
|
|
|
explicit constexpr CrossCompartmentWrapper(unsigned aFlags,
|
|
|
|
bool aHasPrototype = false,
|
2014-08-29 00:47:16 +04:00
|
|
|
bool aHasSecurityPolicy = false)
|
|
|
|
: Wrapper(CROSS_COMPARTMENT | aFlags, aHasPrototype, aHasSecurityPolicy) {
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-10-08 21:09:08 +04:00
|
|
|
/* Standard internal methods. */
|
2015-03-29 01:22:11 +03:00
|
|
|
virtual bool getOwnPropertyDescriptor(
|
|
|
|
JSContext* cx, HandleObject wrapper, HandleId id,
|
2016-01-28 13:28:04 +03:00
|
|
|
MutableHandle<PropertyDescriptor> desc) const override;
|
2015-03-29 01:22:11 +03:00
|
|
|
virtual bool defineProperty(JSContext* cx, HandleObject wrapper, HandleId id,
|
2016-01-28 13:28:04 +03:00
|
|
|
Handle<PropertyDescriptor> desc,
|
2015-03-29 01:22:11 +03:00
|
|
|
ObjectOpResult& result) const override;
|
|
|
|
virtual bool ownPropertyKeys(JSContext* cx, HandleObject wrapper,
|
2016-02-24 00:42:30 +03:00
|
|
|
AutoIdVector& props) const override;
|
|
|
|
virtual bool delete_(JSContext* cx, HandleObject wrapper, HandleId id,
|
2015-03-29 01:22:11 +03:00
|
|
|
ObjectOpResult& result) const override;
|
2019-02-08 11:17:00 +03:00
|
|
|
virtual bool enumerate(JSContext* cx, HandleObject proxy,
|
|
|
|
AutoIdVector& props) const override;
|
2016-02-24 00:42:30 +03:00
|
|
|
virtual bool getPrototype(JSContext* cx, HandleObject proxy,
|
|
|
|
MutableHandleObject protop) const override;
|
2015-03-29 01:22:11 +03:00
|
|
|
virtual bool setPrototype(JSContext* cx, HandleObject proxy,
|
|
|
|
HandleObject proto,
|
|
|
|
ObjectOpResult& result) const override;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2016-02-24 00:42:30 +03:00
|
|
|
virtual bool getPrototypeIfOrdinary(
|
|
|
|
JSContext* cx, HandleObject proxy, bool* isOrdinary,
|
2015-03-21 19:28:04 +03:00
|
|
|
MutableHandleObject protop) const override;
|
2015-03-29 01:22:11 +03:00
|
|
|
virtual bool setImmutablePrototype(JSContext* cx, HandleObject proxy,
|
|
|
|
bool* succeeded) const override;
|
|
|
|
virtual bool preventExtensions(JSContext* cx, HandleObject wrapper,
|
|
|
|
ObjectOpResult& result) const override;
|
|
|
|
virtual bool isExtensible(JSContext* cx, HandleObject wrapper,
|
|
|
|
bool* extensible) const override;
|
|
|
|
virtual bool has(JSContext* cx, HandleObject wrapper, HandleId id,
|
|
|
|
bool* bp) const override;
|
2015-09-18 01:14:33 +03:00
|
|
|
virtual bool get(JSContext* cx, HandleObject wrapper, HandleValue receiver,
|
2015-03-21 19:28:04 +03:00
|
|
|
HandleId id, MutableHandleValue vp) const override;
|
2015-03-29 01:22:11 +03:00
|
|
|
virtual bool set(JSContext* cx, HandleObject wrapper, HandleId id,
|
|
|
|
HandleValue v, HandleValue receiver,
|
|
|
|
ObjectOpResult& result) const override;
|
|
|
|
virtual bool call(JSContext* cx, HandleObject wrapper,
|
|
|
|
const CallArgs& args) const override;
|
|
|
|
virtual bool construct(JSContext* cx, HandleObject wrapper,
|
|
|
|
const CallArgs& args) const override;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-10-08 21:09:08 +04:00
|
|
|
/* SpiderMonkey extensions. */
|
2015-03-29 01:22:11 +03:00
|
|
|
virtual bool hasOwn(JSContext* cx, HandleObject wrapper, HandleId id,
|
|
|
|
bool* bp) const override;
|
|
|
|
virtual bool getOwnEnumerablePropertyKeys(JSContext* cx, HandleObject wrapper,
|
|
|
|
AutoIdVector& props) const override;
|
|
|
|
virtual bool nativeCall(JSContext* cx, IsAcceptableThis test, NativeImpl impl,
|
2015-08-27 22:18:37 +03:00
|
|
|
const CallArgs& args) const override;
|
2015-03-29 01:22:11 +03:00
|
|
|
virtual bool hasInstance(JSContext* cx, HandleObject wrapper,
|
|
|
|
MutableHandleValue v, bool* bp) const override;
|
|
|
|
virtual const char* className(JSContext* cx,
|
|
|
|
HandleObject proxy) const override;
|
|
|
|
virtual JSString* fun_toString(JSContext* cx, HandleObject wrapper,
|
2017-07-25 14:22:11 +03:00
|
|
|
bool isToSource) const override;
|
2017-07-11 12:31:12 +03:00
|
|
|
virtual RegExpShared* regexp_toShared(JSContext* cx,
|
|
|
|
HandleObject proxy) const override;
|
2015-03-29 01:22:11 +03:00
|
|
|
virtual bool boxedValue_unbox(JSContext* cx, HandleObject proxy,
|
|
|
|
MutableHandleValue vp) const override;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2016-04-04 21:50:12 +03:00
|
|
|
// Allocate CrossCompartmentWrappers in the nursery.
|
|
|
|
virtual bool canNurseryAllocate() const override { return true; }
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-06-27 15:44:04 +04:00
|
|
|
static const CrossCompartmentWrapper singleton;
|
|
|
|
static const CrossCompartmentWrapper singletonWithPrototype;
|
2010-06-25 01:45:32 +04:00
|
|
|
};
|
|
|
|
|
2018-11-19 20:02:47 +03:00
|
|
|
class JS_FRIEND_API OpaqueCrossCompartmentWrapper
|
|
|
|
: public CrossCompartmentWrapper {
|
2015-06-02 17:54:54 +03:00
|
|
|
public:
|
2016-07-09 00:39:53 +03:00
|
|
|
explicit constexpr OpaqueCrossCompartmentWrapper()
|
|
|
|
: CrossCompartmentWrapper(0) {}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-06-02 17:54:54 +03:00
|
|
|
/* Standard internal methods. */
|
|
|
|
virtual bool getOwnPropertyDescriptor(
|
|
|
|
JSContext* cx, HandleObject wrapper, HandleId id,
|
2016-01-28 13:28:04 +03:00
|
|
|
MutableHandle<PropertyDescriptor> desc) const override;
|
2015-06-02 17:54:54 +03:00
|
|
|
virtual bool defineProperty(JSContext* cx, HandleObject wrapper, HandleId id,
|
2016-01-28 13:28:04 +03:00
|
|
|
Handle<PropertyDescriptor> desc,
|
2015-06-02 17:54:54 +03:00
|
|
|
ObjectOpResult& result) const override;
|
|
|
|
virtual bool ownPropertyKeys(JSContext* cx, HandleObject wrapper,
|
2016-02-24 00:42:30 +03:00
|
|
|
AutoIdVector& props) const override;
|
|
|
|
virtual bool delete_(JSContext* cx, HandleObject wrapper, HandleId id,
|
2015-06-02 17:54:54 +03:00
|
|
|
ObjectOpResult& result) const override;
|
2019-02-08 11:17:00 +03:00
|
|
|
virtual bool enumerate(JSContext* cx, HandleObject proxy,
|
|
|
|
AutoIdVector& props) const override;
|
2016-02-24 00:42:30 +03:00
|
|
|
virtual bool getPrototype(JSContext* cx, HandleObject wrapper,
|
|
|
|
MutableHandleObject protop) const override;
|
2015-06-02 17:54:54 +03:00
|
|
|
virtual bool setPrototype(JSContext* cx, HandleObject wrapper,
|
|
|
|
HandleObject proto,
|
|
|
|
ObjectOpResult& result) const override;
|
|
|
|
virtual bool getPrototypeIfOrdinary(
|
2015-08-23 11:10:24 +03:00
|
|
|
JSContext* cx, HandleObject wrapper, bool* isOrdinary,
|
2015-06-02 17:54:54 +03:00
|
|
|
MutableHandleObject protop) const override;
|
|
|
|
virtual bool setImmutablePrototype(JSContext* cx, HandleObject wrapper,
|
|
|
|
bool* succeeded) const override;
|
|
|
|
virtual bool preventExtensions(JSContext* cx, HandleObject wrapper,
|
|
|
|
ObjectOpResult& result) const override;
|
|
|
|
virtual bool isExtensible(JSContext* cx, HandleObject wrapper,
|
|
|
|
bool* extensible) const override;
|
|
|
|
virtual bool has(JSContext* cx, HandleObject wrapper, HandleId id,
|
|
|
|
bool* bp) const override;
|
2015-09-18 01:14:33 +03:00
|
|
|
virtual bool get(JSContext* cx, HandleObject wrapper, HandleValue receiver,
|
2015-06-02 17:54:54 +03:00
|
|
|
HandleId id, MutableHandleValue vp) const override;
|
|
|
|
virtual bool set(JSContext* cx, HandleObject wrapper, HandleId id,
|
|
|
|
HandleValue v, HandleValue receiver,
|
|
|
|
ObjectOpResult& result) const override;
|
|
|
|
virtual bool call(JSContext* cx, HandleObject wrapper,
|
|
|
|
const CallArgs& args) const override;
|
|
|
|
virtual bool construct(JSContext* cx, HandleObject wrapper,
|
|
|
|
const CallArgs& args) const override;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-06-02 17:54:54 +03:00
|
|
|
/* SpiderMonkey extensions. */
|
|
|
|
virtual bool hasOwn(JSContext* cx, HandleObject wrapper, HandleId id,
|
|
|
|
bool* bp) const override;
|
|
|
|
virtual bool getOwnEnumerablePropertyKeys(JSContext* cx, HandleObject wrapper,
|
|
|
|
AutoIdVector& props) const override;
|
2016-06-30 01:04:56 +03:00
|
|
|
virtual bool getBuiltinClass(JSContext* cx, HandleObject wrapper,
|
|
|
|
ESClass* cls) const override;
|
2015-08-23 11:10:24 +03:00
|
|
|
virtual bool isArray(JSContext* cx, HandleObject obj,
|
|
|
|
JS::IsArrayAnswer* answer) const override;
|
2018-12-03 01:21:51 +03:00
|
|
|
virtual bool hasInstance(JSContext* cx, HandleObject wrapper,
|
|
|
|
MutableHandleValue v, bool* bp) const override;
|
2015-06-02 17:54:54 +03:00
|
|
|
virtual const char* className(JSContext* cx,
|
|
|
|
HandleObject wrapper) const override;
|
2017-07-25 14:22:11 +03:00
|
|
|
virtual JSString* fun_toString(JSContext* cx, HandleObject proxy,
|
|
|
|
bool isToSource) const override;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-06-02 17:54:54 +03:00
|
|
|
static const OpaqueCrossCompartmentWrapper singleton;
|
|
|
|
};
|
|
|
|
|
2011-10-04 21:50:25 +04:00
|
|
|
/*
|
|
|
|
* Base class for security wrappers. A security wrapper is potentially hiding
|
|
|
|
* all or part of some wrapped object thus SecurityWrapper defaults to denying
|
|
|
|
* access to the wrappee. This is the opposite of Wrapper which tries to be
|
|
|
|
* completely transparent.
|
|
|
|
*
|
|
|
|
* NB: Currently, only a few ProxyHandler operations are overridden to deny
|
|
|
|
* access, relying on derived SecurityWrapper to block access when necessary.
|
|
|
|
*/
|
|
|
|
template <class Base>
|
2018-11-19 20:02:47 +03:00
|
|
|
class JS_FRIEND_API SecurityWrapper : public Base {
|
2011-10-04 21:50:25 +04:00
|
|
|
public:
|
2016-07-09 00:39:53 +03:00
|
|
|
explicit constexpr SecurityWrapper(unsigned flags, bool hasPrototype = false)
|
2014-08-29 00:47:16 +04:00
|
|
|
: Base(flags, hasPrototype, /* hasSecurityPolicy = */ true) {}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-03-29 01:22:11 +03:00
|
|
|
virtual bool enter(JSContext* cx, HandleObject wrapper, HandleId id,
|
|
|
|
Wrapper::Action act, bool mayThrow,
|
2017-02-02 20:48:49 +03:00
|
|
|
bool* bp) const override;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-03-29 01:22:11 +03:00
|
|
|
virtual bool defineProperty(JSContext* cx, HandleObject wrapper, HandleId id,
|
2016-01-28 13:28:04 +03:00
|
|
|
Handle<PropertyDescriptor> desc,
|
2015-03-29 01:22:11 +03:00
|
|
|
ObjectOpResult& result) const override;
|
|
|
|
virtual bool isExtensible(JSContext* cx, HandleObject wrapper,
|
|
|
|
bool* extensible) const override;
|
|
|
|
virtual bool preventExtensions(JSContext* cx, HandleObject wrapper,
|
|
|
|
ObjectOpResult& result) const override;
|
|
|
|
virtual bool setPrototype(JSContext* cx, HandleObject proxy,
|
|
|
|
HandleObject proto,
|
|
|
|
ObjectOpResult& result) const override;
|
|
|
|
virtual bool setImmutablePrototype(JSContext* cx, HandleObject proxy,
|
|
|
|
bool* succeeded) const override;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-03-29 01:22:11 +03:00
|
|
|
virtual bool nativeCall(JSContext* cx, IsAcceptableThis test, NativeImpl impl,
|
2015-08-27 22:18:37 +03:00
|
|
|
const CallArgs& args) const override;
|
2016-06-30 01:04:56 +03:00
|
|
|
virtual bool getBuiltinClass(JSContext* cx, HandleObject wrapper,
|
|
|
|
ESClass* cls) const override;
|
2015-08-23 11:10:24 +03:00
|
|
|
virtual bool isArray(JSContext* cx, HandleObject wrapper,
|
|
|
|
JS::IsArrayAnswer* answer) const override;
|
2017-07-11 12:31:12 +03:00
|
|
|
virtual RegExpShared* regexp_toShared(JSContext* cx,
|
|
|
|
HandleObject proxy) const override;
|
2015-03-29 01:22:11 +03:00
|
|
|
virtual bool boxedValue_unbox(JSContext* cx, HandleObject proxy,
|
|
|
|
MutableHandleValue vp) const override;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-10-08 21:09:08 +04:00
|
|
|
// Allow isCallable and isConstructor. They used to be class-level, and so
|
|
|
|
// could not be guarded against.
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2012-12-21 10:33:26 +04:00
|
|
|
/*
|
|
|
|
* Allow our subclasses to select the superclass behavior they want without
|
|
|
|
* needing to specify an exact superclass.
|
|
|
|
*/
|
|
|
|
typedef Base Permissive;
|
|
|
|
typedef SecurityWrapper<Base> Restrictive;
|
2011-10-04 21:50:25 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef SecurityWrapper<CrossCompartmentWrapper>
|
|
|
|
CrossCompartmentSecurityWrapper;
|
|
|
|
|
2015-03-29 01:22:11 +03:00
|
|
|
extern JSObject* TransparentObjectWrapper(JSContext* cx, HandleObject existing,
|
|
|
|
HandleObject obj);
|
2010-06-25 01:45:32 +04:00
|
|
|
|
2018-06-14 19:07:31 +03:00
|
|
|
inline bool IsWrapper(const JSObject* obj) {
|
2014-08-28 04:09:06 +04:00
|
|
|
return IsProxy(obj) && GetProxyHandler(obj)->family() == &Wrapper::family;
|
2012-02-21 22:31:35 +04:00
|
|
|
}
|
2012-01-26 17:55:27 +04:00
|
|
|
|
2018-07-06 13:52:03 +03:00
|
|
|
inline bool IsCrossCompartmentWrapper(const JSObject* obj) {
|
|
|
|
return IsWrapper(obj) &&
|
|
|
|
(Wrapper::wrapperHandler(obj)->flags() & Wrapper::CROSS_COMPARTMENT);
|
|
|
|
}
|
|
|
|
|
2018-07-06 13:53:38 +03:00
|
|
|
/* static */ inline const Wrapper* Wrapper::wrapperHandler(
|
|
|
|
const JSObject* wrapper) {
|
|
|
|
MOZ_ASSERT(IsWrapper(wrapper));
|
|
|
|
return static_cast<const Wrapper*>(GetProxyHandler(wrapper));
|
|
|
|
}
|
|
|
|
|
2012-01-26 17:55:27 +04:00
|
|
|
// Given a JSObject, returns that object stripped of wrappers. If
|
2015-11-06 21:03:52 +03:00
|
|
|
// stopAtWindowProxy is true, then this returns the WindowProxy if it was
|
2017-06-07 11:51:26 +03:00
|
|
|
// previously wrapped. Otherwise, this returns the first object for which
|
|
|
|
// JSObject::isWrapper returns false.
|
|
|
|
//
|
|
|
|
// ExposeToActiveJS is called on wrapper targets to allow gray marking
|
|
|
|
// assertions to work while an incremental GC is in progress, but this means
|
|
|
|
// that this cannot be called from the GC or off the main thread.
|
2015-11-06 21:03:52 +03:00
|
|
|
JS_FRIEND_API JSObject* UncheckedUnwrap(JSObject* obj,
|
|
|
|
bool stopAtWindowProxy = true,
|
|
|
|
unsigned* flagsp = nullptr);
|
2012-01-26 17:55:27 +04:00
|
|
|
|
2019-02-02 06:22:29 +03:00
|
|
|
// Given a JSObject, returns that object stripped of wrappers, except
|
|
|
|
// WindowProxy wrappers. At each stage, the wrapper has the opportunity to veto
|
|
|
|
// the unwrap. Null is returned if there are security wrappers that can't be
|
|
|
|
// unwrapped.
|
|
|
|
//
|
|
|
|
// This does a static-only unwrap check: it basically checks whether _all_
|
|
|
|
// globals in the wrapper's source compartment should be able to access the
|
|
|
|
// wrapper target. This won't necessarily return the right thing for the HTML
|
|
|
|
// spec's cross-origin objects (WindowProxy and Location), but is fine to use
|
|
|
|
// when failure to unwrap one of those objects wouldn't be a problem. For
|
|
|
|
// example, if you want to test whether your target object is a specific class
|
|
|
|
// that's not WindowProxy or Location, you can use this.
|
2017-06-07 11:51:26 +03:00
|
|
|
//
|
|
|
|
// ExposeToActiveJS is called on wrapper targets to allow gray marking
|
|
|
|
// assertions to work while an incremental GC is in progress, but this means
|
|
|
|
// that this cannot be called from the GC or off the main thread.
|
2019-02-02 06:22:29 +03:00
|
|
|
JS_FRIEND_API JSObject* CheckedUnwrapStatic(JSObject* obj);
|
|
|
|
|
2012-07-18 15:51:28 +04:00
|
|
|
// Unwrap only the outermost security wrapper, with the same semantics as
|
|
|
|
// above. This is the checked version of Wrapper::wrappedObject.
|
2019-03-01 12:21:11 +03:00
|
|
|
JS_FRIEND_API JSObject* UnwrapOneCheckedStatic(JSObject* obj);
|
2012-07-18 15:51:28 +04:00
|
|
|
|
2019-02-02 06:22:29 +03:00
|
|
|
// Given a JSObject, returns that object stripped of wrappers. At each stage,
|
|
|
|
// the security wrapper has the opportunity to veto the unwrap. If
|
|
|
|
// stopAtWindowProxy is true, then this returns the WindowProxy if it was
|
|
|
|
// previously wrapped. Null is returned if there are security wrappers that
|
|
|
|
// can't be unwrapped.
|
|
|
|
//
|
|
|
|
// ExposeToActiveJS is called on wrapper targets to allow gray marking
|
|
|
|
// assertions to work while an incremental GC is in progress, but this means
|
|
|
|
// that this cannot be called from the GC or off the main thread.
|
|
|
|
//
|
|
|
|
// The JSContext argument will be used for dynamic checks (needed by WindowProxy
|
|
|
|
// and Location) and should represent the Realm doing the unwrapping. It is not
|
|
|
|
// used to throw exceptions; this function never throws.
|
|
|
|
//
|
|
|
|
// This function may be able to GC (and the static analysis definitely thinks it
|
|
|
|
// can), but it still takes a JSObject* argument, because some of its callers
|
|
|
|
// would actually have a bit of a hard time producing a Rooted. And it ends up
|
|
|
|
// having to root internally anyway, because it wants to use the value in a loop
|
|
|
|
// and you can't assign to a HandleObject. What this means is that callers who
|
|
|
|
// plan to use the argument object after they have called this function will
|
|
|
|
// need to root it to avoid hazard failures, even though this function doesn't
|
|
|
|
// require a Handle.
|
|
|
|
JS_FRIEND_API JSObject* CheckedUnwrapDynamic(JSObject* obj, JSContext* cx,
|
|
|
|
bool stopAtWindowProxy = true);
|
|
|
|
|
|
|
|
// Unwrap only the outermost security wrapper, with the same semantics as
|
|
|
|
// above. This is the checked version of Wrapper::wrappedObject.
|
|
|
|
JS_FRIEND_API JSObject* UnwrapOneCheckedDynamic(HandleObject obj, JSContext* cx,
|
|
|
|
bool stopAtWindowProxy = true);
|
|
|
|
|
2017-06-07 11:51:26 +03:00
|
|
|
// Given a JSObject, returns that object stripped of wrappers. This returns the
|
|
|
|
// WindowProxy if it was previously wrapped.
|
|
|
|
//
|
|
|
|
// ExposeToActiveJS is not called on wrapper targets so this can be called from
|
|
|
|
// the GC or off the main thread.
|
|
|
|
JS_FRIEND_API JSObject* UncheckedUnwrapWithoutExpose(JSObject* obj);
|
|
|
|
|
2016-11-30 18:06:06 +03:00
|
|
|
void ReportAccessDenied(JSContext* cx);
|
|
|
|
|
2015-03-29 01:22:11 +03:00
|
|
|
JS_FRIEND_API void NukeCrossCompartmentWrapper(JSContext* cx,
|
|
|
|
JSObject* wrapper);
|
2011-10-04 18:06:54 +04:00
|
|
|
|
2019-01-03 12:04:02 +03:00
|
|
|
// If a cross-compartment wrapper source => target exists, nuke it.
|
|
|
|
JS_FRIEND_API void NukeCrossCompartmentWrapperIfExists(JSContext* cx,
|
|
|
|
JS::Compartment* source,
|
|
|
|
JSObject* target);
|
|
|
|
|
2015-03-29 01:22:11 +03:00
|
|
|
void RemapWrapper(JSContext* cx, JSObject* wobj, JSObject* newTarget);
|
2012-07-04 14:13:01 +04:00
|
|
|
|
2015-03-29 01:22:11 +03:00
|
|
|
JS_FRIEND_API bool RemapAllWrappersForObject(JSContext* cx, JSObject* oldTarget,
|
|
|
|
JSObject* newTarget);
|
2012-07-04 14:13:01 +04:00
|
|
|
|
|
|
|
// API to recompute all cross-compartment wrappers whose source and target
|
|
|
|
// match the given filters.
|
2015-03-29 01:22:11 +03:00
|
|
|
JS_FRIEND_API bool RecomputeWrappers(JSContext* cx,
|
|
|
|
const CompartmentFilter& sourceFilter,
|
|
|
|
const CompartmentFilter& targetFilter);
|
2012-07-04 14:13:01 +04:00
|
|
|
|
2011-10-04 18:06:54 +04:00
|
|
|
} /* namespace js */
|
2010-06-04 02:27:29 +04:00
|
|
|
|
2018-02-21 19:30:19 +03:00
|
|
|
#endif /* js_Wrapper_h */
|