mirror of
https://github.com/servo/servo.git
synced 2025-07-22 23:03:42 +01:00
Check for shadowing properties on DOM proxies. Fixes #12357.
This commit is contained in:
parent
2ad293ca64
commit
4961a513d4
2 changed files with 32 additions and 6 deletions
|
@ -17,7 +17,7 @@ use js::jsapi::JS_GetPropertyDescriptorById;
|
||||||
use js::jsapi::MutableHandleObject;
|
use js::jsapi::MutableHandleObject;
|
||||||
use js::jsapi::{Handle, HandleId, HandleObject, MutableHandle, ObjectOpResult};
|
use js::jsapi::{Handle, HandleId, HandleObject, MutableHandle, ObjectOpResult};
|
||||||
use js::jsapi::{JSContext, JSObject, JSPROP_GETTER, PropertyDescriptor, DOMProxyShadowsResult};
|
use js::jsapi::{JSContext, JSObject, JSPROP_GETTER, PropertyDescriptor, DOMProxyShadowsResult};
|
||||||
use js::jsapi::{JSErrNum, JS_StrictPropertyStub};
|
use js::jsapi::{JSErrNum, JS_StrictPropertyStub, JS_AlreadyHasOwnPropertyById};
|
||||||
use js::jsapi::{JS_DefinePropertyById, JS_NewObjectWithGivenProto, SetDOMProxyInformation};
|
use js::jsapi::{JS_DefinePropertyById, JS_NewObjectWithGivenProto, SetDOMProxyInformation};
|
||||||
use js::jsval::ObjectValue;
|
use js::jsval::ObjectValue;
|
||||||
use libc;
|
use libc;
|
||||||
|
@ -26,12 +26,26 @@ use std::{mem, ptr};
|
||||||
static JSPROXYSLOT_EXPANDO: u32 = 0;
|
static JSPROXYSLOT_EXPANDO: u32 = 0;
|
||||||
|
|
||||||
/// Determine if this id shadows any existing properties for this proxy.
|
/// Determine if this id shadows any existing properties for this proxy.
|
||||||
pub unsafe extern "C" fn shadow_check_callback(_cx: *mut JSContext,
|
pub unsafe extern "C" fn shadow_check_callback(cx: *mut JSContext,
|
||||||
_object: HandleObject,
|
object: HandleObject,
|
||||||
_id: HandleId)
|
id: HandleId)
|
||||||
-> DOMProxyShadowsResult {
|
-> DOMProxyShadowsResult {
|
||||||
// XXX implement me
|
// TODO: support OverrideBuiltins when #12978 is fixed.
|
||||||
DOMProxyShadowsResult::ShadowCheckFailed
|
|
||||||
|
rooted!(in(cx) let expando = get_expando_object(object));
|
||||||
|
if !expando.get().is_null() {
|
||||||
|
let mut has_own = false;
|
||||||
|
if !JS_AlreadyHasOwnPropertyById(cx, expando.handle(), id, &mut has_own) {
|
||||||
|
return DOMProxyShadowsResult::ShadowCheckFailed;
|
||||||
|
}
|
||||||
|
|
||||||
|
if has_own {
|
||||||
|
return DOMProxyShadowsResult::ShadowsViaDirectExpando;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Our expando, if any, didn't shadow, so we're not shadowing at all.
|
||||||
|
DOMProxyShadowsResult::DoesntShadow
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Initialize the infrastructure for DOM proxy objects.
|
/// Initialize the infrastructure for DOM proxy objects.
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
<button onclick="void_method()">measure void method</button>
|
<button onclick="void_method()">measure void method</button>
|
||||||
<button onclick="int_getter()">measure int getter</button>
|
<button onclick="int_getter()">measure int getter</button>
|
||||||
<button onclick="firstChild_getter()">measure firstChild getter</button>
|
<button onclick="firstChild_getter()">measure firstChild getter</button>
|
||||||
|
<button onclick="proxy_firstChild_getter()">measure proxy firstChild getter</button>
|
||||||
<script>
|
<script>
|
||||||
var t = 'TestBinding' in window ? (new TestBinding()) : (new TextEncoder());
|
var t = 'TestBinding' in window ? (new TestBinding()) : (new TextEncoder());
|
||||||
function void_method() {
|
function void_method() {
|
||||||
|
@ -33,4 +34,15 @@ function firstChild_getter() {
|
||||||
var stop = new Date();
|
var stop = new Date();
|
||||||
console.log('firstChild getter: ' + ((stop - start) / count * 1e6) + 'ns');
|
console.log('firstChild getter: ' + ((stop - start) / count * 1e6) + 'ns');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function proxy_firstChild_getter() {
|
||||||
|
var n = document;
|
||||||
|
var start = new Date();
|
||||||
|
var count = 1000000;
|
||||||
|
for (var i = 0; i < count; i++) {
|
||||||
|
var a = n.firstChild;
|
||||||
|
}
|
||||||
|
var stop = new Date();
|
||||||
|
console.log('proxy firstChild getter: ' + ((stop - start) / count * 1e6) + 'ns');
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue