-
-
Save fujidig/1221261 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"use strict"; | |
function loader() Components.classes["@mozilla.org/moz/jssubscript-loader;1"] | |
.getService(Components.interfaces.mozIJSSubScriptLoader); | |
var a = {}; | |
Object.defineProperty(a, "foo", {value: 1, writable: false}); | |
print("* directly assign"); | |
try { | |
var b = {__proto__: a}; | |
b.foo = 2; | |
print(b.foo); | |
} catch(e) { print(e) } | |
print("* with subscript loader"); | |
try { | |
var b = {__proto__: a}; | |
io.writeFile("/tmp/tmp.js", "var foo = 2"); | |
loader().loadSubScript("file:///tmp/tmp.js", b); | |
print(b.foo); | |
} catch(e) { print(e) } | |
print("* with defineProperty"); | |
try { | |
var b = {__proto__: a}; | |
Object.defineProperty(b, "foo", {value: 2, writable: true}); | |
print(b.foo); | |
b.foo = 3; | |
print(b.foo); | |
} catch(e) { print(e) } | |
print("* with __defineGetter__"); | |
try { | |
var b = {__proto__: a}; | |
b.__defineGetter__("foo", function() 2); | |
print(b.foo); | |
} catch(e) { print(e) } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment