Files
palemoon27/dom/bindings/DOMJSProxyHandler.cpp
T
roytam1 869fcffa1f import changes from `dev' branch of rmottola/Arctic-Fox:
- Bug 1262453: IonMonkey - Don't add resume point for constants, r=nbp (b5f8021cf8)
- Bug 1240521 - IonBuilder processSwitchEnd returns ControlStatus_Error on allocation errors. r=h4writer (997738a608)
- Bug 1261361 - Make Vector::infallibleGrowByUninitialized check mReserved instead of mCapacity. r=Waldo (1326f9121f)
- Bug 1254203 - SnapshotIterator::maybeRead use AutoEnterOOMUnsafeRegion instead of MOZ_CRASH. r=jandem (54fa438206)
- Bug 1261324 - Fix bogus return address for star generators' .throw being observed by the profiler in Debugger's onExceptionUnwind in Baseline. (r=jandem) (6e998a7d64)
- Bug 1263899 - Fix readFrameArgsAndLocals to always use maybeRead since it can't recover instructions. (r=nbp) (59288f533b)
- Bug 1265748 - Enable non-Object path in IonBuilder::inlineIsCallable. r=shu (c0de95d84f)
- Bug 1186006 - Assert that all blocks have an entry resume point, excepts for unreachable one added by the Value Numbering. r=sunfish (32e9a56e59)
- Bug 1257089 - Weaken the assertions to account for unreachable annotation added by Range Analysis. r=sunfish (87caf2580a)
- Bug 1263888 - Push TypeBarrier after ArraySlice. r=jandem (28e089137b)
- Bug 1246552 - IonMonkey: Don't eliminate toString on objects and symbols, r=jandem (da7c99d316)
- Bug 1258632 - Distinguish signed/unsigned MDiv/MMod in GVN. r=bbouvier (22dbf55c27)
- Bug 1263532 - Do not make RegExpPrototypeOptimizable and RegExpInstanceOptimizable movable. r=h4writer (9b4c75397f)
- Bug 1248202 - Handle an OOM case in optimization tracking. r=jandem (045d4c002c)
- Bug 1257929 - Special case OSR block to avoid bloating safeInsertTop condition. r=h4writer (738c4abd63)
- Bug 1239075 - RangeAnalysis: Assume that all captured results are used in bailing branches. r=h4writer (a8d6b4b29d)
- Bug 1256702 - Skip the operand of MAssertRecoveredOnBailout encoded in the snapshot. r=h4writer (a4705253af)
- Bug 1263895 - IonMonkey: Check return value of all functions in GVN, r=jandem (351ba8d825)
- Bug 1262453 - IonMonkey: Remove Nops which try to decrease liveness of instructions, but fail, r=bhackett (5f7e221a7a)
- Bug 1124397 - More crash diagnostics. r=nbp (4abe9de4f3)
- Bug 1124397 - Temporary diagnostic patch to help figure out what's going on. r=efaust a=kwierso (d7416f77c4)
- Bug 1124397 - Add more crash diagnostics. r=efaust (130cd14bff)
- Bug 1252326 - Reorder MacroAssembler flush functions to follow the header order. r=bbouvier (c361f37707)
- Quick follow-up to bug 1251225 to fix a possibly overflowing left shift (found by Coverity, rs=h4writer on irc) (7b33f428a5)
- Bug 1256588 - IonMonkey: MIPS64: Don't skip nops on Loongson by runtime flag. r=huangwenjun06 (7aa8d6b5d9)
- Bug 1265601 - OdinMonkey: MIPS: Fix i64 testing infrastructure in Baldr. r=bbouvier (f5dfa86b4d)
- Bug 1263090 - OdinMonkey: MIPS: Implement AsmReinterpretFromI64/ToI64. r=bbouvier (3c0bed4a24)
- Bug 1263094 - IonMonkey: MIPS: Change members to non-virtual in CodeGenerator. r=arai (195bfaa03f)
- Bug 1258253 - IonMonkey: MIPS64: Fix MacroAssembler::branchTestMagic. r=arai (6420433ec0)
- Bug 1258253 - IonMonkey: MIPS64: Fix MacroAssembler::branchValueIsNurseryObject. r=arai (271089e08e)
- Bug 1249895 - Replace unsigned __int128_t with __uint128_t. r=hev (8d29fb5234)
- Bug 1258907 - IonMonkey: MIPS32: Fix MacroAssembler::branchValueIsNurseryObject. r=arai (18ae03452f)
- Bug 1256588 - IonMonkey: MIPS: Implement isLoongson. r=huangwenjun06 (d82314788d)
- Bug 1260694 - IonMonkey: MIPS: Inline get MIPS flags. r=huangwenjun06 (caf060f2ed)
- Bug 1258277 - OdinMonkey: MIPS: Leave ARCH_BITS for CPUID. r=huangwenjun06 (8d2ce72d21)
- Bug 1263090 - OdinMonkey: MIPS: Implement AsmReinterpret. r=bbouvier (d1a98954e1)
- Bug 1258293 - IonMonkey: MIPS: Refactor float-point Not by conditional move. r=arai (269c5d3be9)
- Bug 1254369 - IonMonkey: MIPS: Clean up broken assertions. r=arai (aedad3d82a)
- Bug 1254369 - IonMonkey: MIPS: Fix header files missing in MacroAssembler. r=arai (c8b291d450)
- Bug 1250370 - IonMonkey: MIPS: Fix stack alignment checking in EmitBaselineEnterStubFrame. r=nbp (77cd114731)
- Bug 1247312 - Don't generate invalid LDRD instructions on ARM. r=nbp (440e999cf7)
- Bug 1258999: Check for OOM after flushing pools when merging MacroAssemblers; r=efaust (ad22c913ff)
- Bug 1234408 - Fix ARM assembler to bind labels on OOM to silence ~Label assert. r=bbouvier (a4b3f716b1)
- Bug 1254106 - IonMonkey: Disable assertion of incorrect labels on OOM on ARM, like on x86 and x64, r=jandem (86b143ff42)
- cleanup (1a71c7a761)
- Bug 1263040 - Add Intl.getCanonicalLocales. r=jwalden (999911b0b3)
- Bug 1259540 - Fix missing header include that breaks FILES_PER_UNIFIED_FILE=1. r=till (247f599cd9)
- Bug 1263118 - Fix replace substitution without any capture. r=till (c6d500b683)
- Bug 1265449: Remove static assumption about SIMD objects; r=jonco (cfe92c4636)
- Bug 1259600 - Divert typed arrays passed to Array.sort to a typed array specific sort; r=till (f91e07bb1b)
- Bug 1260673 - Stop using _DefineDataProperty in MoveHoles; r=jorendorff (e476f59b01)
- Bug 1260673 - Ensure that Array.sort works with sealed objects; r=jorendorff (6aba58306d)
- Bug 1261813: Ensure the argument to wasmBinaryToText always has a buffer; r=luke (7c86782427)
- Bug 1204562 - GetMethod should not box the receiver argument. r=till (8977188519)
- Bug 552533 - Support thiscall Win32 ABI for js-ctypes. Original patch is dwitte. r=jorendorff (3179fe82fb)
- Bug 1252958 - Implement Debugger.adoptDebuggeeValue;r=jimb (bb1eed3603)
- Bug 1261904 - Refactor Debugger.Object.getErrorMessageName; r=jimb (414b03ce1a)
- Bug 1256560 - Implement AnimationEffectTiming WebIDL. r=birtles, r=smaug (123bc00be6)
- Bug 1244643 - Part 1: Implement AnimationEffectTiming easing. r=hiro (958cde39eb)
- Bug 1244640 - implement AnimationEffectTiming iterations r=hiro (30420e3e22)
- Bug 1255710 - Part 0: Rename test_animation_property_state.html to test_animation_performance_warning.html. r=birtles (7c463acc9d)
- Bug 1255710 - Part 1: Remove all unnecessary t.step_func. r=birtles (b8586a3f6c)
- Bug 1255710 - Part 2: Enable tests for 'transform-style: preserve-3d'. r=birtles (35038639a8)
- Bug 1254840 - Use longer animation duration to avoid intermittent failures on slow platforms. r=dholbert (a0574ebd59)
- Bug 1254881 - Fix animation duration in dom/animation/test/chrome/test_running_on_compositor.html. r=hiro (db038a67ec)
- Bug 1256503 - Part 1: Use MS_PER_SEC instead of human-misreadable digits in animation tests. r=dholbert (ad420d4760)
- Bug 1256503 - Part 2: Increase some test animation durations to be at least 100 seconds. r=dholbert (8ea14b30f0)
- Bug 1244633 - Part 1: implement AnimationEffectTiming delay. r=birtles (94d1be534a)
- Bug 1244633 - Part 2: append tests for delay. r=birtles (cd685f1fe4)
- Bug 1244643 - Part 2: Append tests for easing. r=hiro (9f563a4636)
- Bug 1263631 - Update web-platform-tests to revision 8d896c2015ab1e50ad00a0013700f87813d9364c, a=testonly (71b25211b1)
- Bug 1244643 - Part 3: Move common test cases to a new file. r=hiro (7ee5afd9db)
- Bug 1255718. Remove the unused JSContext argument of AudioBuffer::Create. r=ehsan (c7d2112794)
- Bug 684208 - make dispatchEvent()'s return value to follow the spec, r=masayuki (4a8372e2fb)
- Bug 1223980 - Add iterable<ArrayBuffer,MediaKeyStatus> to MediaKeyStatusMap. r=bz (bcc52aabde)
- Bug 1260417 - Part a: Add a comment about the compartment of CallbackObject::mCallback; r=bz (2abca927f9)
- Bug 1260417 - Part c: Stop mentioning requests around CallSetup::mRootedCallable; r=bz (bb507b8f40)
- Bug 1260417 - Part b: Depend on AutoEntryScript to find an appropriate JSContext CallSetup; r=bz (e1b8fd132b)
- remove specific PM check (d7fae861af)
- minor cleanup (a47c325ad1)
- Bug 1254858: P4. Allow to pass mimetype in constructor. r=kentuckyfriedtakahe (3627f6bb0a)
- Bug 1254858: P5. Add h264 decoding gtest. r=kentuckyfriedtakahe (0bb7873e4f)
- Bug 1254858: P6. Add VP9 decoding gtest. r=kentuckyfriedtakahe (6940369a73)
- Bug 1254858: P8. Change default preferences value if prefs don't exist. r=kentuckyfriedtakahe (1516f43986)
- Bug 1247866: Avoid modifying hashtable during iteration, when iterating over redirects for saved files, to avoid tripping fatal assertion. r=njn (94f77efaad)
- bug 1230065 consider arrow size in dropdown minimum widget size r=acomminos (cd67908374)
- bug 1261277 use GtkTextView to get an appropriate color for resizers r=acomminos (b8b2df0ebf)
- bug 1197165 apply tooltip style class when creating window instead of when drawing r=acomminos (c58078774f)
- Bug 1257811 - set min-height for input widgets. r=karlt (43c5507346)
- bug 1199602 give existing wrap_gtk_window_check_resize internal linkage r=acomminos (ef8fe19a89)
- bug 1199602 emit resume-events on GdkFrameClock if flush/resume not balanced at dispose r=acomminos (16d79ac0cd)
- Bug 1249604 - Don't use gtk_drag_set_icon_surface on GTK versions that use X SHAPE for dnd with cairo. r=karlt (3e7b1f3aaf)
- Bug 1262634 - Avoid undefined reference to moz_gtk_get_entry_min_height in builds specifying cairo-gtk2 toolkit. r=karlt (112c35a394)
2024-05-08 09:45:48 +08:00

292 lines
8.1 KiB
C++

/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* 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/. */
#include "mozilla/dom/DOMJSProxyHandler.h"
#include "xpcpublic.h"
#include "xpcprivate.h"
#include "XPCWrapper.h"
#include "WrapperFactory.h"
#include "nsDOMClassInfo.h"
#include "nsWrapperCacheInlines.h"
#include "mozilla/dom/BindingUtils.h"
#include "jsapi.h"
using namespace JS;
namespace mozilla {
namespace dom {
jsid s_length_id = JSID_VOID;
bool
DefineStaticJSVals(JSContext* cx)
{
return AtomizeAndPinJSString(cx, s_length_id, "length");
}
const char DOMProxyHandler::family = 0;
js::DOMProxyShadowsResult
DOMProxyShadows(JSContext* cx, JS::Handle<JSObject*> proxy, JS::Handle<jsid> id)
{
JS::Rooted<JSObject*> expando(cx, DOMProxyHandler::GetExpandoObject(proxy));
JS::Value v = js::GetProxyExtra(proxy, JSPROXYSLOT_EXPANDO);
bool isOverrideBuiltins = !v.isObject() && !v.isUndefined();
if (expando) {
bool hasOwn;
if (!JS_AlreadyHasOwnPropertyById(cx, expando, id, &hasOwn))
return js::ShadowCheckFailed;
if (hasOwn) {
return isOverrideBuiltins ?
js::ShadowsViaIndirectExpando : js::ShadowsViaDirectExpando;
}
}
if (!isOverrideBuiltins) {
// Our expando, if any, didn't shadow, so we're not shadowing at all.
return js::DoesntShadow;
}
bool hasOwn;
if (!GetProxyHandler(proxy)->hasOwn(cx, proxy, id, &hasOwn))
return js::ShadowCheckFailed;
return hasOwn ? js::Shadows : js::DoesntShadowUnique;
}
// Store the information for the specialized ICs.
struct SetDOMProxyInformation
{
SetDOMProxyInformation() {
js::SetDOMProxyInformation((const void*) &DOMProxyHandler::family,
JSPROXYSLOT_EXPANDO, DOMProxyShadows);
}
};
SetDOMProxyInformation gSetDOMProxyInformation;
// static
JSObject*
DOMProxyHandler::GetAndClearExpandoObject(JSObject* obj)
{
MOZ_ASSERT(IsDOMProxy(obj), "expected a DOM proxy object");
JS::Value v = js::GetProxyExtra(obj, JSPROXYSLOT_EXPANDO);
if (v.isUndefined()) {
return nullptr;
}
if (v.isObject()) {
js::SetProxyExtra(obj, JSPROXYSLOT_EXPANDO, UndefinedValue());
xpc::ObjectScope(obj)->RemoveDOMExpandoObject(obj);
} else {
js::ExpandoAndGeneration* expandoAndGeneration =
static_cast<js::ExpandoAndGeneration*>(v.toPrivate());
v = expandoAndGeneration->expando;
if (v.isUndefined()) {
return nullptr;
}
expandoAndGeneration->expando = UndefinedValue();
}
return &v.toObject();
}
// static
JSObject*
DOMProxyHandler::EnsureExpandoObject(JSContext* cx, JS::Handle<JSObject*> obj)
{
NS_ASSERTION(IsDOMProxy(obj), "expected a DOM proxy object");
JS::Value v = js::GetProxyExtra(obj, JSPROXYSLOT_EXPANDO);
if (v.isObject()) {
return &v.toObject();
}
js::ExpandoAndGeneration* expandoAndGeneration;
if (!v.isUndefined()) {
expandoAndGeneration = static_cast<js::ExpandoAndGeneration*>(v.toPrivate());
if (expandoAndGeneration->expando.isObject()) {
return &expandoAndGeneration->expando.toObject();
}
} else {
expandoAndGeneration = nullptr;
}
JS::Rooted<JSObject*> expando(cx,
JS_NewObjectWithGivenProto(cx, nullptr, nullptr));
if (!expando) {
return nullptr;
}
nsISupports* native = UnwrapDOMObject<nsISupports>(obj);
nsWrapperCache* cache;
CallQueryInterface(native, &cache);
if (expandoAndGeneration) {
cache->PreserveWrapper(native);
expandoAndGeneration->expando.setObject(*expando);
return expando;
}
if (!xpc::ObjectScope(obj)->RegisterDOMExpandoObject(obj)) {
return nullptr;
}
cache->SetPreservingWrapper(true);
js::SetProxyExtra(obj, JSPROXYSLOT_EXPANDO, ObjectValue(*expando));
return expando;
}
bool
DOMProxyHandler::preventExtensions(JSContext* cx, JS::Handle<JSObject*> proxy,
JS::ObjectOpResult& result) const
{
// always extensible per WebIDL
return result.failCantPreventExtensions();
}
bool
DOMProxyHandler::isExtensible(JSContext *cx, JS::Handle<JSObject*> proxy, bool *extensible) const
{
*extensible = true;
return true;
}
bool
BaseDOMProxyHandler::getOwnPropertyDescriptor(JSContext* cx,
JS::Handle<JSObject*> proxy,
JS::Handle<jsid> id,
MutableHandle<PropertyDescriptor> desc) const
{
return getOwnPropDescriptor(cx, proxy, id, /* ignoreNamedProps = */ false,
desc);
}
bool
DOMProxyHandler::defineProperty(JSContext* cx, JS::Handle<JSObject*> proxy, JS::Handle<jsid> id,
Handle<PropertyDescriptor> desc,
JS::ObjectOpResult &result, bool *defined) const
{
if (desc.hasGetterObject() && desc.setter() == JS_StrictPropertyStub) {
return result.failGetterOnly();
}
if (xpc::WrapperFactory::IsXrayWrapper(proxy)) {
return result.succeed();
}
JS::Rooted<JSObject*> expando(cx, EnsureExpandoObject(cx, proxy));
if (!expando) {
return false;
}
if (!JS_DefinePropertyById(cx, expando, id, desc, result)) {
return false;
}
*defined = true;
return true;
}
bool
DOMProxyHandler::set(JSContext *cx, Handle<JSObject*> proxy, Handle<jsid> id,
Handle<JS::Value> v, Handle<JS::Value> receiver,
ObjectOpResult &result) const
{
MOZ_ASSERT(!xpc::WrapperFactory::IsXrayWrapper(proxy),
"Should not have a XrayWrapper here");
bool done;
if (!setCustom(cx, proxy, id, v, &done)) {
return false;
}
if (done) {
return result.succeed();
}
// Make sure to ignore our named properties when checking for own
// property descriptors for a set.
JS::Rooted<PropertyDescriptor> ownDesc(cx);
if (!getOwnPropDescriptor(cx, proxy, id, /* ignoreNamedProps = */ true,
&ownDesc)) {
return false;
}
return js::SetPropertyIgnoringNamedGetter(cx, proxy, id, v, receiver, ownDesc, result);
}
bool
DOMProxyHandler::delete_(JSContext* cx, JS::Handle<JSObject*> proxy,
JS::Handle<jsid> id, JS::ObjectOpResult &result) const
{
JS::Rooted<JSObject*> expando(cx);
if (!xpc::WrapperFactory::IsXrayWrapper(proxy) && (expando = GetExpandoObject(proxy))) {
return JS_DeletePropertyById(cx, expando, id, result);
}
return result.succeed();
}
bool
BaseDOMProxyHandler::watch(JSContext* cx, JS::Handle<JSObject*> proxy, JS::Handle<jsid> id,
JS::Handle<JSObject*> callable) const
{
return js::WatchGuts(cx, proxy, id, callable);
}
bool
BaseDOMProxyHandler::unwatch(JSContext* cx, JS::Handle<JSObject*> proxy, JS::Handle<jsid> id) const
{
return js::UnwatchGuts(cx, proxy, id);
}
bool
BaseDOMProxyHandler::ownPropertyKeys(JSContext* cx,
JS::Handle<JSObject*> proxy,
JS::AutoIdVector& props) const
{
return ownPropNames(cx, proxy, JSITER_OWNONLY | JSITER_HIDDEN | JSITER_SYMBOLS, props);
}
bool
BaseDOMProxyHandler::getOwnEnumerablePropertyKeys(JSContext* cx,
JS::Handle<JSObject*> proxy,
JS::AutoIdVector& props) const
{
return ownPropNames(cx, proxy, JSITER_OWNONLY, props);
}
bool
DOMProxyHandler::setCustom(JSContext* cx, JS::Handle<JSObject*> proxy, JS::Handle<jsid> id,
JS::Handle<JS::Value> v, bool *done) const
{
*done = false;
return true;
}
//static
JSObject *
DOMProxyHandler::GetExpandoObject(JSObject *obj)
{
MOZ_ASSERT(IsDOMProxy(obj), "expected a DOM proxy object");
JS::Value v = js::GetProxyExtra(obj, JSPROXYSLOT_EXPANDO);
if (v.isObject()) {
return &v.toObject();
}
if (v.isUndefined()) {
return nullptr;
}
js::ExpandoAndGeneration* expandoAndGeneration =
static_cast<js::ExpandoAndGeneration*>(v.toPrivate());
v = expandoAndGeneration->expando;
return v.isUndefined() ? nullptr : &v.toObject();
}
} // namespace dom
} // namespace mozilla