1
0
Fork 0

Merge branch 'master' of github.com:mikegerwitz/easejs

closure/master
Mike Gerwitz 2010-12-23 15:59:57 -05:00
commit 3ef2a28e24
16 changed files with 116 additions and 85 deletions

View File

@ -80,6 +80,8 @@ exports.secureFallback = function( val )
} }
secure_fallback = !!val; secure_fallback = !!val;
exports.defineSecureProp = getDefineSecureProp();
return exports; return exports;
}; };
@ -96,32 +98,7 @@ exports.secureFallback = function( val )
* *
* @return {undefined} * @return {undefined}
*/ */
exports.defineSecureProp = function( obj, prop, value ) exports.defineSecureProp = getDefineSecureProp();
{
if ( secure_fallback )
{
obj[ prop ] = value;
}
else
{
try
{
Object.defineProperty( obj, prop,
{
value: value,
enumerable: false,
writable: false,
configurable: false,
});
}
catch ( e )
{
// if there's an error (ehem, IE8), fall back
obj[ prop ] = value;
}
}
}
/** /**
@ -479,3 +456,51 @@ exports.arrayShrink = function( items )
return arr_new; return arr_new;
} }
/**
* Appropriately returns defineSecureProp implementation to avoid check on each
* invocation
*
* @return {function( Object, string, * )}
*/
function getDefineSecureProp()
{
// falls back to simply defining a normal property
var fallback = function( obj, prop, value )
{
obj[ prop ] = value;
};
if ( secure_fallback )
{
return fallback;
}
else
{
// uses ECMAScript 5's Object.defineProperty() method
return function( obj, prop, value )
{
try
{
Object.defineProperty( obj, prop,
{
value: value,
enumerable: false,
writable: false,
configurable: false,
});
}
catch ( e )
{
// let's not have this happen again, as repeatedly throwing
// exceptions will do nothing but slow down the system
exports.secureFallback( true );
// if there's an error (ehem, IE8), fall back
fallback( obj, prop, value );
}
};
}
}

View File

@ -22,5 +22,25 @@
* @package test * @package test
*/ */
require.paths.unshift( __dirname + '/../lib' ); /**
* Library path
* @type {string}
*/
exports.PATH_LIB = require( 'path' ).normalize( __dirname + '/../lib' );
/**
* Returns requested module from the library path
*
* This method abstracts require() implementation so that the tests may be more
* easily implemented elsewhere (e.g. client-side)
*
* @param {string} module module id
*
* @return {Object} module exports
*/
exports.require = function( module )
{
return require( exports.PATH_LIB + '/' + module );
}

View File

@ -22,12 +22,11 @@
* @package test * @package test
*/ */
require( './common' ); var common = require( './common' ),
assert = require( 'assert' ),
var assert = require( 'assert' ), Class = common.require( 'class' ),
Class = require( '../lib/class' ), abstractMethod = common.require( 'class' ).abstractMethod,
abstractMethod = require( '../lib/class' ).abstractMethod, util = common.require( 'util' );
util = require( '../lib/util' );
// not abstract // not abstract
var Foo = Class.extend( {} ); var Foo = Class.extend( {} );

View File

@ -22,10 +22,9 @@
* @package test * @package test
*/ */
require( './common' ); var common = require( './common' ),
assert = require( 'assert' ),
var assert = require( 'assert' ), Class = common.require( 'class' );
Class = require( 'class' );
// these two variables are declared outside of the class to ensure that they // these two variables are declared outside of the class to ensure that they
// will still be set even if the context of the constructor is wrong // will still be set even if the context of the constructor is wrong

View File

@ -22,10 +22,9 @@
* @package test * @package test
*/ */
require( './common' ); var common = require( './common' ),
assert = require( 'assert' ),
var assert = require( 'assert' ), Class = common.require( 'class' );
Class = require( 'class' );
var foo_props = { var foo_props = {
one: 1, one: 1,

View File

@ -28,10 +28,9 @@ if ( Object.prototype.__defineGetter__ === undefined )
return; return;
} }
require( './common' ); var common = require( './common' ),
assert = require( 'assert' ),
var assert = require( 'assert' ), Class = common.require( 'class' );
Class = require( 'class' );
var Foo = Class.extend( var Foo = Class.extend(

View File

@ -22,10 +22,9 @@
* @package test * @package test
*/ */
require( './common' ); var common = require( './common' ),
assert = require( 'assert' ),
var assert = require( 'assert' ), Class = common.require( 'class' );
Class = require( 'class' );
var Foo = Class.extend( var Foo = Class.extend(
{ {

View File

@ -22,10 +22,9 @@
* @package test * @package test
*/ */
require( './common' ); var common = require( './common' ),
assert = require( 'assert' ),
var assert = require( 'assert' ), Class = common.require( 'class' );
Class = require( 'class' );
assert.ok( assert.ok(

View File

@ -22,10 +22,9 @@
* @package test * @package test
*/ */
require( './common' ); var common = require( './common' ),
assert = require( 'assert' ),
var assert = require( 'assert' ), Class = common.require( 'class' ),
Class = require( 'class' ),
Script = process.binding( 'evals' ).Script, Script = process.binding( 'evals' ).Script,
sandbox = {}; sandbox = {};

View File

@ -22,10 +22,9 @@
* @package test * @package test
*/ */
require( './common' ); var common = require( './common' ),
assert = require( 'assert' ),
var assert = require( 'assert' ), Class = common.require( 'class' ),
Class = require( 'class' ),
index = require( '../' ); index = require( '../' );

View File

@ -22,10 +22,9 @@
* @package test * @package test
*/ */
require( './common' ); var common = require( './common' ),
assert = require( 'assert' ),
var assert = require( 'assert' ), Interface = common.require( 'interface' ),
Interface = require( 'interface' ),
abstractMethod = Interface.abstractMethod; abstractMethod = Interface.abstractMethod;

View File

@ -22,10 +22,9 @@
* @package test * @package test
*/ */
require( './common' ); var common = require( './common' ),
assert = require( 'assert' ),
var assert = require( 'assert' ), Interface = common.require( 'interface' ),
Interface = require( 'interface' ),
abstractMethod = Interface.abstractMethod; abstractMethod = Interface.abstractMethod;
var FooType = Interface.extend(); var FooType = Interface.extend();

View File

@ -22,10 +22,9 @@
* @package test * @package test
*/ */
require( './common' ); var common = require( './common' ),
assert = require( 'assert' ),
var assert = require( 'assert' ), util = common.require( 'util' );
util = require( '../lib/util' );
var arr = [ 1, 2, 3 ], var arr = [ 1, 2, 3 ],
obj = { a: 1, b: 2 }; obj = { a: 1, b: 2 };

View File

@ -22,10 +22,9 @@
* @package test * @package test
*/ */
require( './common' ); var common = require( './common' ),
assert = require( 'assert' ),
var assert = require( 'assert' ), util = common.require( 'util' );
util = require( '../lib/util' );
var obj = {}, var obj = {},
val = 'bar'; val = 'bar';

View File

@ -22,10 +22,9 @@
* @package test * @package test
*/ */
require( './common' ); var common = require( './common' ),
assert = require( 'assert' ),
var assert = require( 'assert' ), propCopy = common.require( 'util' ).propCopy;
propCopy = require( '../lib/util' ).propCopy;
var props = { var props = {
one: 1, one: 1,

View File

@ -22,10 +22,9 @@
* @package test * @package test
*/ */
require( './common' ); var common = require( './common' ),
assert = require( 'assert' ),
var assert = require( 'assert' ), util = common.require( 'util' );
util = require( '../lib/util' );
var data = { var data = {
// scalars (properties) // scalars (properties)