Bug 1683281 - Part 2: Move proxy handler utility functions from DOMJSProxyHandler.h to ProxyHandlerUtils.h; r=peterv
Depends on D103469 Differential Revision: https://phabricator.services.mozilla.com/D112277
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
#include "js/Proxy.h"
|
||||
#include "mozilla/Maybe.h"
|
||||
#include "mozilla/dom/BrowsingContext.h"
|
||||
#include "mozilla/dom/ProxyHandlerUtils.h"
|
||||
#include "mozilla/dom/RemoteObjectProxy.h"
|
||||
#include "mozilla/dom/WindowBinding.h"
|
||||
#include "mozilla/dom/WindowProxyHolder.h"
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
|
||||
#include "WindowNamedPropertiesHandler.h"
|
||||
#include "mozilla/dom/EventTargetBinding.h"
|
||||
#include "mozilla/dom/ProxyHandlerUtils.h"
|
||||
#include "mozilla/dom/WindowBinding.h"
|
||||
#include "mozilla/dom/WindowProxyHolder.h"
|
||||
#include "nsContentUtils.h"
|
||||
|
||||
@@ -111,7 +111,6 @@
|
||||
#include "mozilla/dom/ContentFrameMessageManager.h"
|
||||
#include "mozilla/dom/ContentMediaController.h"
|
||||
#include "mozilla/dom/CustomElementRegistry.h"
|
||||
#include "mozilla/dom/DOMJSProxyHandler.h"
|
||||
#include "mozilla/dom/DebuggerNotification.h"
|
||||
#include "mozilla/dom/DebuggerNotificationBinding.h"
|
||||
#include "mozilla/dom/DebuggerNotificationManager.h"
|
||||
@@ -151,6 +150,7 @@
|
||||
#include "mozilla/dom/PopupBlocker.h"
|
||||
#include "mozilla/dom/PrimitiveConversions.h"
|
||||
#include "mozilla/dom/Promise.h"
|
||||
#include "mozilla/dom/ProxyHandlerUtils.h"
|
||||
#include "mozilla/dom/RootedDictionary.h"
|
||||
#include "mozilla/dom/ScriptLoader.h"
|
||||
#include "mozilla/dom/ScriptSettings.h"
|
||||
|
||||
@@ -39,6 +39,7 @@
|
||||
#include "mozilla/dom/Storage.h"
|
||||
#include "mozilla/dom/MaybeCrossOriginObject.h"
|
||||
#include "mozilla/dom/Performance.h"
|
||||
#include "mozilla/dom/ProxyHandlerUtils.h"
|
||||
#include "mozilla/dom/StorageEvent.h"
|
||||
#include "mozilla/dom/StorageEventBinding.h"
|
||||
#include "mozilla/dom/StorageNotifierService.h"
|
||||
|
||||
@@ -18194,6 +18194,10 @@ class CGBindingRoot(CGThing):
|
||||
d.concrete and d.proxy for d in descriptors
|
||||
)
|
||||
|
||||
bindingHeaders["mozilla/dom/ProxyHandlerUtils.h"] = any(
|
||||
d.concrete and d.proxy for d in descriptors
|
||||
)
|
||||
|
||||
bindingHeaders["js/String.h"] = any(
|
||||
d.needsMissingPropUseCounters for d in descriptors
|
||||
)
|
||||
|
||||
@@ -7,20 +7,12 @@
|
||||
#ifndef mozilla_dom_DOMJSProxyHandler_h
|
||||
#define mozilla_dom_DOMJSProxyHandler_h
|
||||
|
||||
#include "mozilla/Attributes.h"
|
||||
#include "mozilla/Likely.h"
|
||||
#include "mozilla/Assertions.h"
|
||||
#include "mozilla/Maybe.h"
|
||||
#include "mozilla/TextUtils.h"
|
||||
|
||||
#include "jsapi.h"
|
||||
#include "js/Object.h" // JS::GetClass
|
||||
#include "js/Proxy.h"
|
||||
#include "js/String.h" // JS::AtomToLinearString, JS::GetLinearString{CharAt,Length}
|
||||
#include "nsString.h"
|
||||
|
||||
// XXX Avoid including this (and maybe some of those above by moving inline
|
||||
// function bodies out)
|
||||
#include "jsfriendapi.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
@@ -173,42 +165,6 @@ inline const DOMProxyHandler* GetDOMProxyHandler(JSObject* obj) {
|
||||
return static_cast<const DOMProxyHandler*>(js::GetProxyHandler(obj));
|
||||
}
|
||||
|
||||
extern jsid s_length_id;
|
||||
|
||||
// A return value of UINT32_MAX indicates "not an array index". Note, in
|
||||
// particular, that UINT32_MAX itself is not a valid array index in general.
|
||||
inline uint32_t GetArrayIndexFromId(JS::Handle<jsid> id) {
|
||||
// Much like js::IdIsIndex, except with a fast path for "length" and another
|
||||
// fast path for starting with a lowercase ascii char. Is that second one
|
||||
// really needed? I guess it is because StringIsArrayIndex is out of line...
|
||||
// as of now, use id.get() instead of id otherwise operands mismatch error
|
||||
// occurs.
|
||||
if (MOZ_LIKELY(id.isInt())) {
|
||||
return id.toInt();
|
||||
}
|
||||
if (MOZ_LIKELY(id.get() == s_length_id)) {
|
||||
return UINT32_MAX;
|
||||
}
|
||||
if (MOZ_UNLIKELY(!id.isAtom())) {
|
||||
return UINT32_MAX;
|
||||
}
|
||||
|
||||
JSLinearString* str = JS::AtomToLinearString(id.toAtom());
|
||||
if (MOZ_UNLIKELY(JS::GetLinearStringLength(str) == 0)) {
|
||||
return UINT32_MAX;
|
||||
}
|
||||
|
||||
char16_t firstChar = JS::GetLinearStringCharAt(str, 0);
|
||||
if (MOZ_LIKELY(IsAsciiLowercaseAlpha(firstChar))) {
|
||||
return UINT32_MAX;
|
||||
}
|
||||
|
||||
uint32_t i;
|
||||
return js::StringIsArrayIndex(str, &i) ? i : UINT32_MAX;
|
||||
}
|
||||
|
||||
inline bool IsArrayIndex(uint32_t index) { return index < UINT32_MAX; }
|
||||
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
||||
|
||||
65
dom/bindings/ProxyHandlerUtils.h
Normal file
65
dom/bindings/ProxyHandlerUtils.h
Normal file
@@ -0,0 +1,65 @@
|
||||
/* -*- 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/. */
|
||||
|
||||
#ifndef mozilla_dom_ProxyHandlerUtils_h
|
||||
#define mozilla_dom_ProxyHandlerUtils_h
|
||||
|
||||
#include "mozilla/Attributes.h"
|
||||
#include "mozilla/Likely.h"
|
||||
#include "mozilla/Maybe.h"
|
||||
#include "mozilla/TextUtils.h"
|
||||
|
||||
#include "js/Id.h"
|
||||
#include "js/Object.h" // JS::GetClass
|
||||
#include "js/PropertyDescriptor.h"
|
||||
#include "js/String.h" // JS::AtomToLinearString, JS::GetLinearString{CharAt,Length}
|
||||
#include "js/TypeDecls.h"
|
||||
|
||||
#include "jsfriendapi.h" // js::StringIsArrayIndex
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
||||
extern jsid s_length_id;
|
||||
|
||||
// A return value of UINT32_MAX indicates "not an array index". Note, in
|
||||
// particular, that UINT32_MAX itself is not a valid array index in general.
|
||||
inline uint32_t GetArrayIndexFromId(JS::Handle<jsid> id) {
|
||||
// Much like js::IdIsIndex, except with a fast path for "length" and another
|
||||
// fast path for starting with a lowercase ascii char. Is that second one
|
||||
// really needed? I guess it is because StringIsArrayIndex is out of line...
|
||||
// as of now, use id.get() instead of id otherwise operands mismatch error
|
||||
// occurs.
|
||||
if (MOZ_LIKELY(id.isInt())) {
|
||||
return id.toInt();
|
||||
}
|
||||
if (MOZ_LIKELY(id.get() == s_length_id)) {
|
||||
return UINT32_MAX;
|
||||
}
|
||||
if (MOZ_UNLIKELY(!id.isAtom())) {
|
||||
return UINT32_MAX;
|
||||
}
|
||||
|
||||
JSLinearString* str = JS::AtomToLinearString(id.toAtom());
|
||||
if (MOZ_UNLIKELY(JS::GetLinearStringLength(str) == 0)) {
|
||||
return UINT32_MAX;
|
||||
}
|
||||
|
||||
char16_t firstChar = JS::GetLinearStringCharAt(str, 0);
|
||||
if (MOZ_LIKELY(IsAsciiLowercaseAlpha(firstChar))) {
|
||||
return UINT32_MAX;
|
||||
}
|
||||
|
||||
uint32_t i;
|
||||
return js::StringIsArrayIndex(str, &i) ? i : UINT32_MAX;
|
||||
}
|
||||
|
||||
inline bool IsArrayIndex(uint32_t index) { return index < UINT32_MAX; }
|
||||
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
||||
#endif /* mozilla_dom_ProxyHandlerUtils_h */
|
||||
@@ -18,10 +18,10 @@
|
||||
#include "mozilla/Maybe.h"
|
||||
#include "mozilla/dom/BindingNames.h"
|
||||
#include "mozilla/dom/DOMJSClass.h"
|
||||
#include "mozilla/dom/DOMJSProxyHandler.h"
|
||||
#include "mozilla/dom/Exceptions.h"
|
||||
#include "mozilla/dom/JSSlots.h"
|
||||
#include "mozilla/dom/PrototypeList.h"
|
||||
#include "mozilla/dom/ProxyHandlerUtils.h"
|
||||
#include "mozilla/dom/RegisterBindings.h"
|
||||
#include "nsGlobalWindow.h"
|
||||
#include "nsTHashtable.h"
|
||||
|
||||
@@ -45,6 +45,7 @@ EXPORTS.mozilla.dom += [
|
||||
"Nullable.h",
|
||||
"PinnedStringId.h",
|
||||
"PrimitiveConversions.h",
|
||||
"ProxyHandlerUtils.h",
|
||||
"Record.h",
|
||||
"RemoteObjectProxy.h",
|
||||
"RootedDictionary.h",
|
||||
|
||||
@@ -33,6 +33,7 @@
|
||||
#include "mozilla/FloatingPoint.h"
|
||||
#include "mozilla/dom/BindingUtils.h"
|
||||
#include "mozilla/dom/BrowsingContext.h"
|
||||
#include "mozilla/dom/ProxyHandlerUtils.h"
|
||||
#include "mozilla/dom/WindowBinding.h"
|
||||
#include "mozilla/dom/WindowProxyHolder.h"
|
||||
#include "mozilla/dom/XrayExpandoClass.h"
|
||||
|
||||
Reference in New Issue
Block a user