Merge pull request #4678 from atom/writable-member-functions
Make remote member functions writable/configurable
This commit is contained in:
commit
2bd167663d
4 changed files with 16 additions and 3 deletions
|
@ -16,7 +16,7 @@ const FUNCTION_PROPERTIES = [
|
||||||
let rendererFunctions = {};
|
let rendererFunctions = {};
|
||||||
|
|
||||||
// Return the description of object's members:
|
// Return the description of object's members:
|
||||||
let getObjectMemebers = function(object) {
|
let getObjectMembers = function(object) {
|
||||||
let names = Object.getOwnPropertyNames(object);
|
let names = Object.getOwnPropertyNames(object);
|
||||||
// For Function, we should not override following properties even though they
|
// For Function, we should not override following properties even though they
|
||||||
// are "own" properties.
|
// are "own" properties.
|
||||||
|
@ -46,7 +46,7 @@ let getObjectPrototype = function(object) {
|
||||||
if (proto === null || proto === Object.prototype)
|
if (proto === null || proto === Object.prototype)
|
||||||
return null;
|
return null;
|
||||||
return {
|
return {
|
||||||
members: getObjectMemebers(proto),
|
members: getObjectMembers(proto),
|
||||||
proto: getObjectPrototype(proto),
|
proto: getObjectPrototype(proto),
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
@ -101,7 +101,7 @@ var valueToMeta = function(sender, value, optimizeSimpleObject) {
|
||||||
// passed to renderer we would assume the renderer keeps a reference of
|
// passed to renderer we would assume the renderer keeps a reference of
|
||||||
// it.
|
// it.
|
||||||
meta.id = objectsRegistry.add(sender, value);
|
meta.id = objectsRegistry.add(sender, value);
|
||||||
meta.members = getObjectMemebers(value);
|
meta.members = getObjectMembers(value);
|
||||||
meta.proto = getObjectPrototype(value);
|
meta.proto = getObjectPrototype(value);
|
||||||
} else if (meta.type === 'buffer') {
|
} else if (meta.type === 'buffer') {
|
||||||
meta.value = Array.prototype.slice.call(value, 0);
|
meta.value = Array.prototype.slice.call(value, 0);
|
||||||
|
|
|
@ -110,6 +110,8 @@ let setObjectMembers = function(object, metaId, members) {
|
||||||
return metaToValue(ret);
|
return metaToValue(ret);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
descriptor.writable = true;
|
||||||
|
descriptor.configurable = true;
|
||||||
descriptor.value = remoteMemberFunction;
|
descriptor.value = remoteMemberFunction;
|
||||||
} else if (member.type === 'get') {
|
} else if (member.type === 'get') {
|
||||||
descriptor.get = function() {
|
descriptor.get = function() {
|
||||||
|
|
|
@ -63,6 +63,16 @@ describe('ipc module', function() {
|
||||||
var obj = new call.constructor;
|
var obj = new call.constructor;
|
||||||
assert.equal(obj.test, 'test');
|
assert.equal(obj.test, 'test');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('can reassign and delete its member functions', function() {
|
||||||
|
var remoteFunctions = remote.require(path.join(fixtures, 'module', 'function.js'));
|
||||||
|
assert.equal(remoteFunctions.aFunction(), 1127);
|
||||||
|
|
||||||
|
remoteFunctions.aFunction = function () { return 1234; };
|
||||||
|
assert.equal(remoteFunctions.aFunction(), 1234);
|
||||||
|
|
||||||
|
assert.equal(delete remoteFunctions.aFunction, true);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('remote value in browser', function() {
|
describe('remote value in browser', function() {
|
||||||
|
|
1
spec/fixtures/module/function.js
vendored
Normal file
1
spec/fixtures/module/function.js
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
exports.aFunction = function() { return 1127; };
|
Loading…
Add table
Add a link
Reference in a new issue