Bug 875348 - Added support for non ASCII sandbox names. r?bholley
MozReview-Commit-ID: HHQBEzrLTYJ
--- a/js/xpconnect/idl/xpccomponents.idl
+++ b/js/xpconnect/idl/xpccomponents.idl
@@ -680,17 +680,17 @@ interface nsIXPCComponents_Utils : nsISu
* compartment (the same one used by the memory reporter machinery).
*
* Unwraps cross-compartment wrappers first.
*
* The string formats and values may change at any time. Do not depend on
* this from addon code.
*/
[implicit_jscontext]
- ACString getCompartmentLocation(in jsval obj);
+ AUTF8String getCompartmentLocation(in jsval obj);
[implicit_jscontext]
void setAddonInterposition(in ACString addonId, in nsIAddonInterposition interposition);
/*
* Enables call interpositions from addon scopes to any functions in the scope of |target|.
*/
[implicit_jscontext]
--- a/js/xpconnect/src/Sandbox.cpp
+++ b/js/xpconnect/src/Sandbox.cpp
@@ -1599,20 +1599,21 @@ OptionsBase::ParseString(const char* nam
if (!found)
return true;
if (!value.isString()) {
JS_ReportErrorASCII(mCx, "Expected a string value for property %s", name);
return false;
}
- char* tmp = JS_EncodeString(mCx, value.toString());
- NS_ENSURE_TRUE(tmp, false);
- prop.Assign(tmp, strlen(tmp));
- js_free(tmp);
+ nsAutoJSString strVal;
+ if (!strVal.init(mCx, value.toString())) {
+ return false;
+ }
+ prop.Assign(NS_ConvertUTF16toUTF8(strVal));
return true;
}
/*
* Helper that tries to get a string property from the options object.
*/
bool
OptionsBase::ParseString(const char* name, nsString& prop)
new file mode 100644
--- /dev/null
+++ b/js/xpconnect/tests/unit/test_bug875348.js
@@ -0,0 +1,9 @@
+const Cu = Components.utils;
+function run_test() {
+ // Check if a sandbox with a non ASCII string as a title
+ // can be referenced with said string
+ var some_non_ascii_string = "漢字";
+ var sb = new Cu.Sandbox(null, { sandboxName: some_non_ascii_string });
+ var location = Cu.getCompartmentLocation(sb);
+ Assert.ok(location.indexOf(some_non_ascii_string) >= 0);
+}
\ No newline at end of file
--- a/js/xpconnect/tests/unit/xpcshell.ini
+++ b/js/xpconnect/tests/unit/xpcshell.ini
@@ -39,16 +39,17 @@ support-files =
[test_bug849730.js]
[test_bug851895.js]
[test_bug853709.js]
[test_bug854558.js]
[test_bug856067.js]
[test_bug868675.js]
[test_bug867486.js]
[test_bug872772.js]
+[test_bug875348.js]
[test_bug885800.js]
[test_bug930091.js]
[test_bug976151.js]
[test_bug1001094.js]
[test_bug1021312.js]
[test_bug1033253.js]
[test_bug1033920.js]
[test_bug1033927.js]