Skip to content

Commit

Permalink
Added better support for call and apply
Browse files Browse the repository at this point in the history
  • Loading branch information
FremyCompany committed Mar 9, 2018
1 parent 3784793 commit b1927d5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
21 changes: 12 additions & 9 deletions proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ void function() {
};

var shouldBeWrapped = function(f) {
return !isAlreadyWrapped(f) && isFromThisRealm(f) && (!~objectsToNeverWrapProperties.indexOf(f)) && (typeof(f) == 'function' ? isNativeFunction(f) : (f.constructor ? f.constructor !== Object && isNativeFunction(f.constructor) : false));
return !isAlreadyWrapped(f) && isFromThisRealm(f) && (!~objectsToNeverWrapProperties.indexOf(f)) && (typeof(f) == 'function' ? isNativeFunction(f) : (f.constructor ? f.constructor !== Object && isNativeFunction(unbox(f.constructor)) : false));
}

Function.prototype.bind = function() {
Expand Down Expand Up @@ -655,14 +655,17 @@ void function() {
}
}

/*
objectsToNeverWrap.forEach(o => {
o[isAlreadyWrapped] = true; //TODO: unsafe for prototypes because we don't check hasOwnProperty(isAlreadyWrapped) in usage
if(typeof(o) == 'function') {
o[isKnownNativeFunction] = true;
}
});
*/
// add special support for "call" and "apply"
var functionCall = Function.prototype.call;
var functionApply = Function.prototype.apply;
functionToString.call = functionCall.call = functionApply.call = functionCall;
functionToString.apply = functionCall.apply = functionApply.apply = functionApply;
Function.prototype.call = function(obj, ...args) {
return wrapInProxy(functionCall.call(this, obj, ...args));
}
Function.prototype.apply = function(obj, args) {
return wrapInProxy(functionCall.call(this, obj, ...args));
}

//
// Now it is time to wrap the important objects of this realm
Expand Down
8 changes: 7 additions & 1 deletion tests/000.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,10 @@ a.remove();
// test2
var o = new Option();
o.textContent = 'option';
o.defaultSelected = true;
o.defaultSelected = true;

// test3
var d1 = document.createElement.call(document, 'DIV');
d1.__expando = 'div';
var d2 = document.createElement.apply(document, ['DIV']);
d2.__expando = 'div';

0 comments on commit b1927d5

Please sign in to comment.