JE

 view release on metacpan or  search on metacpan

t/10.01-execution-context-definitions.t  view on Meta::CPAN


for(var f_var3; 0;)    { function f_for_func   (){} var f_for_var    }
for(var f_var4 in this){ function f_for_in_func(){} var f_for_in_var }

with(ok) { function f_with_func(){} var f_with_var }

switch(38){
	case 2:  function f_case_func   (){} var f_case_var
	default: function f_default_func(){} var f_default_var
	case 3:  function f_case2_func  (){} var f_case2_var
}

labelled_statement: { function f_label_func(){} }
anither_labelled_statement: var f_label_var

try      { function f_try_func    (){} var f_try_var     }
catch(me){ function f_catch_func  (){} var f_catch_var   }
finally  { function f_finally_func(){} var f_finally_var }

}())


// ---------------------------------------------------
/* Tests 72-4: initialisation of function params */

0,function(two,parameters){
	ok((two,!('two' in this)) && (parameters,!('parameters' in this)),
		'function params are added to the call object')
}()
,function(home,sweet,home){
	ok(home == 'less',
		'last param is used when two share the same name')
}('me','want','less')
,function(home,sweet,home){
	ok(typeof home == 'undefined',
		'last param is used when two share the same name,' +
		' even if it\'s not defined')
}('Me','Tarzan')


// ---------------------------------------------------
/* Tests 75-84: attributes set by function declarations */

ok(typeof Infinity == 'function',
	'function declarations clobber existing vars')
ok(RegExp() === 'else',
	'function declarations are applied in order')
ok(propertyIsEnumerable('Infinity'),
	'function declarations clobber the DontEnum attribute')
ok(!delete RegExp,
	'function declarations clobber the DontDelete attribute')
readonly = 100
ok(readonly == 100,
	'function declarations clobber the ReadOnly attribute')

function RegExp(){ return 'something' }
function RegExp(){ return 'else'      }
function Infinity(){}
function readonly(){}

eval('function NaN(){} function readonly2(){}')
ok(propertyIsEnumerable('NaN'), 'eval("function NaN...") removes DontEnum')
readonly2 = void 0;
ok(readonly2 === void 2,
	'eval("function readonly_var ...") removes ReadOnly attribute')
ok(delete NaN,	
	'eval("function NaN...") removes DontDelete attribute')

,function(thing){
	ok(!delete thing, 'params are undeleteable')
	eval('function thing(){}')
	ok(delete thing,
		'function(){eval("function ...")} removes the ' +
		'DontDelete attribute')
}()


// ---------------------------------------------------
/* Tests 85-95: attributes set by var declarations */

ok(typeof Boolean === 'function',
	'var declarations leave existing vars alone')
ok(my_other_variable === void 0,
	'vars created by var declarations are initially undefined')
ok(!propertyIsEnumerable('undefined'),
	'var declarations leave the DontEnum attribute of existing vars ' +
	'alone')
ok(delete Boolean,
	'var declarations leave the DontDelete attribute of existing ' +
	'vars alone')
readonly3 = 100
ok(readonly3 != 100,
	'var declarations leave the ReadOnly attribute of existing vars ' +
	'alone')
ok(!delete my_other_variable,
	'vars created by "var" are undeleteable in global code')
eval('var yet_another_var')
ok(delete yet_another_var,
	'vars created by "var" in eval code are deletable')
ok(propertyIsEnumerable('my_other_variable'), 
	'var declarations create enumerable properties')
my_other_variable = 33
ok(my_other_variable === 33, 'var-declared vars are not readonly')

var Boolean = 'RegExp';
var undefined = 73;
var my_other_variable = 3;
var readonly3 = 322;

0,function(thing){
	var eee;
	ok(!delete eee,
		'var-declared vars are undeleteable in function code')
	var thing;
	ok(thing === 356,
	     'var declarations leave existing vars alone in function code')
}(356)


// ===================================================
// 10.1.4 Scope Chain and Identifier Resolution
// ===================================================

/* Tests 96-9 */

obj = { some_property: 7, another_property: 8 }
this.some_property = 9



( run in 2.146 seconds using v1.01-cache-2.11-cpan-98e64b0badf )