From 2f3202994dca20b7f176e0045b801bb3b7732b8f Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Tue, 13 Nov 2012 00:26:55 -0800 Subject: [PATCH] Bug 810520. Correctly handle static methods and attributes in the NativeProperties structs that Xrays use. r=peterv Note that at this point we actaully do Xrays for all of our various property types, except in worker code. The real substantive change here is the change to what usedForXrays returns. The rest is minor cleanup. --- dom/bindings/Codegen.py | 31 +++++++++---------- .../chrome/test_sandbox_bindings.xul | 10 ++++++ 2 files changed, 25 insertions(+), 16 deletions(-) diff --git a/dom/bindings/Codegen.py b/dom/bindings/Codegen.py index 522f0c340359..e33b4d2b2302 100644 --- a/dom/bindings/Codegen.py +++ b/dom/bindings/Codegen.py @@ -1027,11 +1027,8 @@ class PropertyDefiner: return "s" + self.name return "nullptr" def usedForXrays(self): - # We only need Xrays for methods, attributes and constants, but in - # workers there are no Xrays. - return (self.name is "Methods" or self.name is "Attributes" or - self.name is "UnforgeableAttributes" or - self.name is "Constants") and not self.descriptor.workers + # No Xrays in workers. + return not self.descriptor.workers def __str__(self): # We only need to generate id arrays for things that will end @@ -1364,14 +1361,11 @@ class CGNativeProperties(CGList): for array in properties.arrayNames(): propertyArray = getattr(properties, array) if check(propertyArray): - if descriptor.workers: - props = "%(name)s, nullptr, %(name)s_specs" + if propertyArray.usedForXrays(): + ids = "%(name)s_ids" else: - if propertyArray.usedForXrays(): - ids = "%(name)s_ids" - else: - ids = "nullptr" - props = "%(name)s, " + ids + ", %(name)s_specs" + ids = "nullptr" + props = "%(name)s, " + ids + ", %(name)s_specs" props = (props % { 'name': propertyArray.variableName(chrome) }) else: @@ -1380,10 +1374,15 @@ class CGNativeProperties(CGList): return CGWrapper(CGIndenter(CGList(nativeProps, ",\n")), pre="static const NativeProperties %s = {\n" % name, post="\n};") - - regular = generateNativeProperties("sNativeProperties", False) - chrome = generateNativeProperties("sChromeOnlyNativeProperties", True) - CGList.__init__(self, [regular, chrome], "\n\n") + + nativeProperties = [] + if properties.hasNonChromeOnly(): + nativeProperties.append( + generateNativeProperties("sNativeProperties", False)) + if properties.hasChromeOnly(): + nativeProperties.append( + generateNativeProperties("sChromeOnlyNativeProperties", True)) + CGList.__init__(self, nativeProperties, "\n\n") def declare(self): return "" diff --git a/dom/tests/mochitest/chrome/test_sandbox_bindings.xul b/dom/tests/mochitest/chrome/test_sandbox_bindings.xul index 930abf1145f8..c8ef4ebac40f 100644 --- a/dom/tests/mochitest/chrome/test_sandbox_bindings.xul +++ b/dom/tests/mochitest/chrome/test_sandbox_bindings.xul @@ -181,6 +181,16 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=741267 ok(false, "NodeList.prototype manipulation via an Xray shouldn't throw" + e); } + try { + var url = Components.utils.evalInSandbox("URL", sandbox); + for (var i in url) { + url[i]; + } + ok(true, "We didn't crash!"); + } catch (e) { + ok(false, "URL interface object manipulation via an Xray shouldn't throw" + e); + } + SimpleTest.finish(); }