Skip to content

Commit

Permalink
Merge pull request #162 from bryan-m-hughes/timob-13358-1_0_X
Browse files Browse the repository at this point in the history
Timob 13358 1 0 x
  • Loading branch information
nebrius committed Apr 17, 2013
2 parents ce99af4 + aebfdc6 commit 9b7e294
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 17 deletions.
63 changes: 55 additions & 8 deletions lib/Base.js
Original file line number Diff line number Diff line change
Expand Up @@ -3347,7 +3347,8 @@ ObjectProtoHasOwnPropertyFunc,
ObjectProtoIsPrototypeOfFunc,
ObjectProtoPropertyIsEnumerableFunc,
addNonEnumerableProperty,
wrapNativeCall
wrapNativeCall,
convertToUnknown
*/

/*****************************************
Expand Down Expand Up @@ -3637,14 +3638,19 @@ function ArrayProtoPopFunc(className) {
FunctionTypeBase.call(this, 0, className || 'Function');
}
util.inherits(ArrayProtoPopFunc, FunctionTypeBase);
ArrayProtoPopFunc.prototype.callFunction = wrapNativeCall(function callFunction(thisVal, args) {
ArrayProtoPopFunc.prototype.callFunction = wrapNativeCall(function callFunction(thisVal, args, options) {

// Variable declarations
var o,
len,
indx,
element;

if (options && options.isAmbiguousContext) {
convertToUnknown(thisVal);
return new UnknownType();
}

// Validate the parameters
if (areAnyUnknown((args || []).concat(thisVal))) {
return new UnknownType();
Expand Down Expand Up @@ -3687,14 +3693,19 @@ function ArrayProtoPushFunc(className) {
FunctionTypeBase.call(this, 1, className || 'Function');
}
util.inherits(ArrayProtoPushFunc, FunctionTypeBase);
ArrayProtoPushFunc.prototype.callFunction = wrapNativeCall(function callFunction(thisVal, args) {
ArrayProtoPushFunc.prototype.callFunction = wrapNativeCall(function callFunction(thisVal, args, options) {

// Steps 1-4
var o,
n,
items,
lengthNumber;

if (options && options.isAmbiguousContext) {
convertToUnknown(thisVal);
return new UnknownType();
}

// Validate the parameters
if (areAnyUnknown((args || []).concat(thisVal))) {
return new UnknownType();
Expand Down Expand Up @@ -3734,7 +3745,7 @@ function ArrayProtoReverseFunc(className) {
FunctionTypeBase.call(this, 0, className || 'Function');
}
util.inherits(ArrayProtoReverseFunc, FunctionTypeBase);
ArrayProtoReverseFunc.prototype.callFunction = wrapNativeCall(function callFunction(thisVal, args) {
ArrayProtoReverseFunc.prototype.callFunction = wrapNativeCall(function callFunction(thisVal, args, options) {

// Variable declarations
var o,
Expand All @@ -3747,6 +3758,11 @@ ArrayProtoReverseFunc.prototype.callFunction = wrapNativeCall(function callFunct
lowerExists,
upperExists;

if (options && options.isAmbiguousContext) {
convertToUnknown(thisVal);
return new UnknownType();
}

// Validate the parameters
if (areAnyUnknown((args || []).concat(thisVal))) {
return new UnknownType();
Expand Down Expand Up @@ -3796,7 +3812,7 @@ function ArrayProtoShiftFunc(className) {
FunctionTypeBase.call(this, 0, className || 'Function');
}
util.inherits(ArrayProtoShiftFunc, FunctionTypeBase);
ArrayProtoShiftFunc.prototype.callFunction = wrapNativeCall(function callFunction(thisVal, args) {
ArrayProtoShiftFunc.prototype.callFunction = wrapNativeCall(function callFunction(thisVal, args, options) {

// Variable declarations
var o,
Expand All @@ -3806,6 +3822,11 @@ ArrayProtoShiftFunc.prototype.callFunction = wrapNativeCall(function callFunctio
from,
to;

if (options && options.isAmbiguousContext) {
convertToUnknown(thisVal);
return new UnknownType();
}

// Validate the parameters
if (areAnyUnknown((args || []).concat(thisVal))) {
return new UnknownType();
Expand Down Expand Up @@ -3927,14 +3948,19 @@ function ArrayProtoSortFunc(className) {
FunctionTypeBase.call(this, 0, className || 'Function');
}
util.inherits(ArrayProtoSortFunc, FunctionTypeBase);
ArrayProtoSortFunc.prototype.callFunction = wrapNativeCall(function callFunction(thisVal, args) {
ArrayProtoSortFunc.prototype.callFunction = wrapNativeCall(function callFunction(thisVal, args, options) {

// Variable declarations
var compareFn,
o,
len,
changes;

if (options && options.isAmbiguousContext) {
convertToUnknown(thisVal);
return new UnknownType();
}

// Validate the parameters
if (areAnyUnknown((args || []).concat(thisVal))) {
return new UnknownType();
Expand Down Expand Up @@ -4114,7 +4140,7 @@ function ArrayProtoSpliceFunc(className) {
FunctionTypeBase.call(this, 2, className || 'Function');
}
util.inherits(ArrayProtoSpliceFunc, FunctionTypeBase);
ArrayProtoSpliceFunc.prototype.callFunction = wrapNativeCall(function callFunction(thisVal, args) {
ArrayProtoSpliceFunc.prototype.callFunction = wrapNativeCall(function callFunction(thisVal, args, options) {

// Variable declarations
var start,
Expand All @@ -4131,6 +4157,11 @@ ArrayProtoSpliceFunc.prototype.callFunction = wrapNativeCall(function callFuncti
items,
itemCount;

if (options && options.isAmbiguousContext) {
convertToUnknown(thisVal);
return new UnknownType();
}

// Validate the parameters
if (areAnyUnknown((args || []).concat(thisVal))) {
return new UnknownType();
Expand Down Expand Up @@ -4231,7 +4262,7 @@ function ArrayProtoUnshiftFunc(className) {
FunctionTypeBase.call(this, 1, className || 'Function');
}
util.inherits(ArrayProtoUnshiftFunc, FunctionTypeBase);
ArrayProtoUnshiftFunc.prototype.callFunction = wrapNativeCall(function callFunction(thisVal, args) {
ArrayProtoUnshiftFunc.prototype.callFunction = wrapNativeCall(function callFunction(thisVal, args, options) {

// Variable declarations
var o = toObject(thisVal),
Expand All @@ -4243,6 +4274,11 @@ ArrayProtoUnshiftFunc.prototype.callFunction = wrapNativeCall(function callFunct
j,
items;

if (options && options.isAmbiguousContext) {
convertToUnknown(thisVal);
return new UnknownType();
}

// Validate the parameters
if (areAnyUnknown((args || []).concat(thisVal))) {
return new UnknownType();
Expand Down Expand Up @@ -8083,6 +8119,17 @@ function isCallable(input) {
}
}

/**
* Converts a value to unknown "in-place"
*
* @method
* @param {module:Base.BaseType} value The value to convert
*/
exports.convertToUnknown = convertToUnknown;
function convertToUnknown (value) {
UnknownType.call(value);
}

/**
* The Strict Equality Comparison Algorithm
*
Expand Down
11 changes: 11 additions & 0 deletions lib/base/conversion.js
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,17 @@ function isCallable(input) {
}
}

/**
* Converts a value to unknown "in-place"
*
* @method
* @param {module:Base.BaseType} value The value to convert
*/
exports.convertToUnknown = convertToUnknown;
function convertToUnknown (value) {
UnknownType.call(value);
}

/**
* The Strict Equality Comparison Algorithm
*
Expand Down
52 changes: 44 additions & 8 deletions lib/base/prototypes/array.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ ObjectProtoHasOwnPropertyFunc,
ObjectProtoIsPrototypeOfFunc,
ObjectProtoPropertyIsEnumerableFunc,
addNonEnumerableProperty,
wrapNativeCall
wrapNativeCall,
convertToUnknown
*/

/*****************************************
Expand Down Expand Up @@ -315,14 +316,19 @@ function ArrayProtoPopFunc(className) {
FunctionTypeBase.call(this, 0, className || 'Function');
}
util.inherits(ArrayProtoPopFunc, FunctionTypeBase);
ArrayProtoPopFunc.prototype.callFunction = wrapNativeCall(function callFunction(thisVal, args) {
ArrayProtoPopFunc.prototype.callFunction = wrapNativeCall(function callFunction(thisVal, args, options) {

// Variable declarations
var o,
len,
indx,
element;

if (options && options.isAmbiguousContext) {
convertToUnknown(thisVal);
return new UnknownType();
}

// Validate the parameters
if (areAnyUnknown((args || []).concat(thisVal))) {
return new UnknownType();
Expand Down Expand Up @@ -365,14 +371,19 @@ function ArrayProtoPushFunc(className) {
FunctionTypeBase.call(this, 1, className || 'Function');
}
util.inherits(ArrayProtoPushFunc, FunctionTypeBase);
ArrayProtoPushFunc.prototype.callFunction = wrapNativeCall(function callFunction(thisVal, args) {
ArrayProtoPushFunc.prototype.callFunction = wrapNativeCall(function callFunction(thisVal, args, options) {

// Steps 1-4
var o,
n,
items,
lengthNumber;

if (options && options.isAmbiguousContext) {
convertToUnknown(thisVal);
return new UnknownType();
}

// Validate the parameters
if (areAnyUnknown((args || []).concat(thisVal))) {
return new UnknownType();
Expand Down Expand Up @@ -412,7 +423,7 @@ function ArrayProtoReverseFunc(className) {
FunctionTypeBase.call(this, 0, className || 'Function');
}
util.inherits(ArrayProtoReverseFunc, FunctionTypeBase);
ArrayProtoReverseFunc.prototype.callFunction = wrapNativeCall(function callFunction(thisVal, args) {
ArrayProtoReverseFunc.prototype.callFunction = wrapNativeCall(function callFunction(thisVal, args, options) {

// Variable declarations
var o,
Expand All @@ -425,6 +436,11 @@ ArrayProtoReverseFunc.prototype.callFunction = wrapNativeCall(function callFunct
lowerExists,
upperExists;

if (options && options.isAmbiguousContext) {
convertToUnknown(thisVal);
return new UnknownType();
}

// Validate the parameters
if (areAnyUnknown((args || []).concat(thisVal))) {
return new UnknownType();
Expand Down Expand Up @@ -474,7 +490,7 @@ function ArrayProtoShiftFunc(className) {
FunctionTypeBase.call(this, 0, className || 'Function');
}
util.inherits(ArrayProtoShiftFunc, FunctionTypeBase);
ArrayProtoShiftFunc.prototype.callFunction = wrapNativeCall(function callFunction(thisVal, args) {
ArrayProtoShiftFunc.prototype.callFunction = wrapNativeCall(function callFunction(thisVal, args, options) {

// Variable declarations
var o,
Expand All @@ -484,6 +500,11 @@ ArrayProtoShiftFunc.prototype.callFunction = wrapNativeCall(function callFunctio
from,
to;

if (options && options.isAmbiguousContext) {
convertToUnknown(thisVal);
return new UnknownType();
}

// Validate the parameters
if (areAnyUnknown((args || []).concat(thisVal))) {
return new UnknownType();
Expand Down Expand Up @@ -605,14 +626,19 @@ function ArrayProtoSortFunc(className) {
FunctionTypeBase.call(this, 0, className || 'Function');
}
util.inherits(ArrayProtoSortFunc, FunctionTypeBase);
ArrayProtoSortFunc.prototype.callFunction = wrapNativeCall(function callFunction(thisVal, args) {
ArrayProtoSortFunc.prototype.callFunction = wrapNativeCall(function callFunction(thisVal, args, options) {

// Variable declarations
var compareFn,
o,
len,
changes;

if (options && options.isAmbiguousContext) {
convertToUnknown(thisVal);
return new UnknownType();
}

// Validate the parameters
if (areAnyUnknown((args || []).concat(thisVal))) {
return new UnknownType();
Expand Down Expand Up @@ -792,7 +818,7 @@ function ArrayProtoSpliceFunc(className) {
FunctionTypeBase.call(this, 2, className || 'Function');
}
util.inherits(ArrayProtoSpliceFunc, FunctionTypeBase);
ArrayProtoSpliceFunc.prototype.callFunction = wrapNativeCall(function callFunction(thisVal, args) {
ArrayProtoSpliceFunc.prototype.callFunction = wrapNativeCall(function callFunction(thisVal, args, options) {

// Variable declarations
var start,
Expand All @@ -809,6 +835,11 @@ ArrayProtoSpliceFunc.prototype.callFunction = wrapNativeCall(function callFuncti
items,
itemCount;

if (options && options.isAmbiguousContext) {
convertToUnknown(thisVal);
return new UnknownType();
}

// Validate the parameters
if (areAnyUnknown((args || []).concat(thisVal))) {
return new UnknownType();
Expand Down Expand Up @@ -909,7 +940,7 @@ function ArrayProtoUnshiftFunc(className) {
FunctionTypeBase.call(this, 1, className || 'Function');
}
util.inherits(ArrayProtoUnshiftFunc, FunctionTypeBase);
ArrayProtoUnshiftFunc.prototype.callFunction = wrapNativeCall(function callFunction(thisVal, args) {
ArrayProtoUnshiftFunc.prototype.callFunction = wrapNativeCall(function callFunction(thisVal, args, options) {

// Variable declarations
var o = toObject(thisVal),
Expand All @@ -921,6 +952,11 @@ ArrayProtoUnshiftFunc.prototype.callFunction = wrapNativeCall(function callFunct
j,
items;

if (options && options.isAmbiguousContext) {
convertToUnknown(thisVal);
return new UnknownType();
}

// Validate the parameters
if (areAnyUnknown((args || []).concat(thisVal))) {
return new UnknownType();
Expand Down
3 changes: 2 additions & 1 deletion lib/rules/AST_Call.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ AST.registerRuleProcessor('AST_Call', function processRule() {

// Call the function, checking if this is a direct call to eval
result = func.callFunction(thisValue, args, {
isDirectEval: Base.getReferencedName(ref) === 'eval'
isDirectEval: Base.getReferencedName(ref) === 'eval',
isAmbiguousContext: Runtime.isAmbiguousBlock()
});

// Store the jump
Expand Down

0 comments on commit 9b7e294

Please sign in to comment.