aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbors-servo <lbergstrom+bors@mozilla.com>2016-07-12 05:50:46 -0700
committerGitHub <noreply@github.com>2016-07-12 05:50:46 -0700
commite2e7013e7629af1b1da4b944798bee00d4eae2d2 (patch)
treea5c8936ee95f900e481f49256c890ddc4c6465fb
parent6d59be17bedbf9a96915b854df8ae8a0cd371831 (diff)
parentfc3b785af1c4e6c96b5c9d0646ac22e92a327787 (diff)
downloadservo-e2e7013e7629af1b1da4b944798bee00d4eae2d2.tar.gz
servo-e2e7013e7629af1b1da4b944798bee00d4eae2d2.zip
Auto merge of #12395 - jdm:nowrap, r=Ms2ger
Avoid calling JS_WrapValue for same-compartment DOM reflectors This change shaves off 15-20ns per iteration of the node.firstChild getter test in tests/html/bindings_perf.html. Based on [similar Gecko code](http://searchfox.org/mozilla-central/rev/f43c9e0ffa92e72dbdbcbf57eecf04a43d46da63/dom/bindings/BindingUtils.h#781). --- - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [X] These changes fix (partially) #12358 <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/12395) <!-- Reviewable:end -->
-rw-r--r--components/script/dom/bindings/codegen/CodegenRust.py13
-rw-r--r--components/script/dom/bindings/conversions.rs16
2 files changed, 17 insertions, 12 deletions
diff --git a/components/script/dom/bindings/codegen/CodegenRust.py b/components/script/dom/bindings/codegen/CodegenRust.py
index 8c0d27afb82..2513b5b92eb 100644
--- a/components/script/dom/bindings/codegen/CodegenRust.py
+++ b/components/script/dom/bindings/codegen/CodegenRust.py
@@ -5533,17 +5533,17 @@ class CGBindingRoot(CGThing):
'js::jsapi::{JSJitInfo_AliasSet, JSJitInfo_ArgType, AutoIdVector, CallArgs, FreeOp}',
'js::jsapi::{JSITER_SYMBOLS, JSPROP_ENUMERATE, JSPROP_PERMANENT, JSPROP_READONLY, JSPROP_SHARED}',
'js::jsapi::{JSCLASS_RESERVED_SLOTS_SHIFT, JSITER_HIDDEN, JSITER_OWNONLY}',
- 'js::jsapi::{GetGlobalForObjectCrossCompartment , GetPropertyKeys, Handle}',
+ 'js::jsapi::{GetPropertyKeys, Handle}',
'js::jsapi::{HandleId, HandleObject, HandleValue, HandleValueArray}',
'js::jsapi::{INTERNED_STRING_TO_JSID, IsCallable, JS_CallFunctionValue}',
- 'js::jsapi::{JS_ComputeThis, JS_CopyPropertiesFrom, JS_ForwardGetPropertyTo}',
+ 'js::jsapi::{JS_CopyPropertiesFrom, JS_ForwardGetPropertyTo}',
'js::jsapi::{JS_GetClass, JS_GetErrorPrototype, JS_GetFunctionPrototype}',
'js::jsapi::{JS_GetGlobalForObject, JS_GetObjectPrototype, JS_GetProperty}',
'js::jsapi::{JS_GetPropertyById, JS_GetPropertyDescriptorById, JS_GetReservedSlot}',
'js::jsapi::{JS_HasProperty, JS_HasPropertyById, JS_InitializePropertiesFromCompatibleNativeObject}',
- 'js::jsapi::{JS_AtomizeAndPinString, JS_IsExceptionPending, JS_NewObject, JS_NewObjectWithGivenProto}',
- 'js::jsapi::{JS_NewObjectWithoutMetadata, JS_NewStringCopyZ, JS_SetProperty}',
- 'js::jsapi::{JS_SetPrototype, JS_SetReservedSlot, JS_WrapValue, JSAutoCompartment}',
+ 'js::jsapi::{JS_AtomizeAndPinString, JS_NewObject, JS_NewObjectWithGivenProto}',
+ 'js::jsapi::{JS_NewObjectWithoutMetadata, JS_SetProperty}',
+ 'js::jsapi::{JS_SetPrototype, JS_SetReservedSlot, JSAutoCompartment}',
'js::jsapi::{JSContext, JSClass, JSFreeOp, JSFunctionSpec}',
'js::jsapi::{JSJitGetterCallArgs, JSJitInfo, JSJitMethodCallArgs, JSJitSetterCallArgs}',
'js::jsapi::{JSNative, JSObject, JSNativeWrapper, JSPropertySpec}',
@@ -5556,8 +5556,7 @@ class CGBindingRoot(CGThing):
'js::jsval::{NullValue, UndefinedValue}',
'js::glue::{CallJitMethodOp, CallJitGetterOp, CallJitSetterOp, CreateProxyHandler}',
'js::glue::{GetProxyPrivate, NewProxyObject, ProxyTraps}',
- 'js::glue::{RUST_FUNCTION_VALUE_TO_JITINFO}',
- 'js::glue::{RUST_JS_NumberValue, RUST_JSID_IS_STRING, int_to_jsid}',
+ 'js::glue::{RUST_JSID_IS_STRING, int_to_jsid}',
'js::glue::AppendToAutoIdVector',
'js::rust::{GCMethods, define_methods, define_properties}',
'dom::bindings',
diff --git a/components/script/dom/bindings/conversions.rs b/components/script/dom/bindings/conversions.rs
index 80911b65e74..01282ea3b1f 100644
--- a/components/script/dom/bindings/conversions.rs
+++ b/components/script/dom/bindings/conversions.rs
@@ -47,9 +47,9 @@ use js::glue::{RUST_JSID_IS_STRING, RUST_JSID_TO_STRING, UnwrapObject};
use js::jsapi::{HandleId, HandleObject, HandleValue, JSClass, JSContext};
use js::jsapi::{JSObject, JSString, JS_GetArrayBufferViewType, JS_GetClass};
use js::jsapi::{JS_GetLatin1StringCharsAndLength, JS_GetObjectAsArrayBufferView};
-use js::jsapi::{JS_GetReservedSlot, JS_GetTwoByteStringCharsAndLength};
+use js::jsapi::{JS_GetReservedSlot, JS_GetTwoByteStringCharsAndLength, ToWindowProxyIfWindow};
use js::jsapi::{JS_IsArrayObject, JS_NewStringCopyN, JS_StringHasLatin1Chars};
-use js::jsapi::{JS_WrapValue, MutableHandleValue, Type};
+use js::jsapi::{JS_WrapValue, MutableHandleValue, Type, IsObjectInContextCompartment};
use js::jsval::{ObjectValue, StringValue};
use js::rust::ToString;
use libc;
@@ -276,9 +276,15 @@ impl ToJSValConvertible for Reflector {
unsafe fn to_jsval(&self, cx: *mut JSContext, rval: MutableHandleValue) {
let obj = self.get_jsobject().get();
assert!(!obj.is_null());
- rval.set(ObjectValue(&*obj));
- if !JS_WrapValue(cx, rval) {
- panic!("JS_WrapValue failed.");
+ let same_compartment = IsObjectInContextCompartment(obj, cx);
+ if same_compartment {
+ rval.set(ObjectValue(&*ToWindowProxyIfWindow(obj)));
+ } else {
+ rval.set(ObjectValue(&*obj));
+
+ if !JS_WrapValue(cx, rval) {
+ panic!("JS_WrapValue failed.");
+ }
}
}
}