Skip to content

Instantly share code, notes, and snippets.

@teramako
Created February 4, 2011 13:50
Show Gist options
  • Select an option

  • Save teramako/811124 to your computer and use it in GitHub Desktop.

Select an option

Save teramako/811124 to your computer and use it in GitHub Desktop.
Firefox3.6のXPCNativeWrapperとFirefox4.0のXrayWrapperの違い
/*
簡易テストのため、Vimperatorの:sourceで実行
wrapされたSandbox上で一方(sd1)に値を代入、もう一方(sd2)で参照をするテスト
Firefox3.6 の場合:
sd1でevalInSandboxした値はsd2からも参照可能。
また、Chrome特権上からも参照可能
Firefox4.0bの場合:
sd2からは参照不可。
また、Chrome特権上からも不可
*/
var win = content.window;
var sd1 = new Cu.Sandbox(win);
sd1.__proto__ = win;
sd1.NAME = "sd1";
var sd2 = new Cu.Sandbox(win);
sd2.__proto__ = win;
sd2.NAME = "sd2";
var res = [];
function test(src, sd, nonpush) {
var name = sd ? sd.NAME : "chrome";
var r = sd ? Cu.evalInSandbox(src, sd) : eval(src);
if (!nonpush)
res.push(name + ":\t" + src + ":\ttypeof: " + typeof(r) + ",\tValue: " + r);
else
res.push("// CODE " + name + ": " + src);
}
test("window.a", sd1); // undefined
test("window.a = 'FOO';", sd1, true);
test("window.a", sd1); // "FOO"
test("window.a", sd2); // undefined
test("sd1.window.a"); // undefined
test("sd2.window.a"); // undefined
alert(
res.join("\n")
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment