Skip to content

Instantly share code, notes, and snippets.

@fujidig
Created September 16, 2011 05:18
Show Gist options
  • Save fujidig/1221261 to your computer and use it in GitHub Desktop.
Save fujidig/1221261 to your computer and use it in GitHub Desktop.
"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