2010-12-20 19:13:27 -05:00
|
|
|
/**
|
|
|
|
* Tests util.defineSecureProp
|
|
|
|
*
|
2013-12-20 01:11:26 -05:00
|
|
|
* Copyright (C) 2010, 2011, 2013 Mike Gerwitz
|
2010-12-20 19:13:27 -05:00
|
|
|
*
|
|
|
|
* This file is part of ease.js.
|
|
|
|
*
|
|
|
|
* ease.js is free software: you can redistribute it and/or modify it under the
|
Relicensed under the GPLv3+
This project was originally LGPLv+-licensed to encourage its use in a community
that is largely copyleft-phobic. After further reflection, that was a mistake,
as adoption is not the important factor here---software freedom is.
When submitting ease.js to the GNU project, it was asked if I would be willing
to relicense it under the GPLv3+; I agreed happily, because there is no reason
why we should provide proprietary software any sort of edge. Indeed, proprietary
JavaScript is a huge problem since it is automatically downloaded on the user's
PC generally without them even knowing, and is a current focus for the FSF. As
such, to remain firm in our stance against proprietary JavaScript, relicensing
made the most sense for GNU.
This is likely to upset current users of ease.js. I am not sure of their
number---I have only seen download counts periodically on npmjs.org---but I know
there are at least a small number. These users are free to continue using the
previous LGPL'd releases, but with the understanding that there will be no
further maintenance (not even bug fixes). If possible, users should use the
GPL-licensed versions and release their software as free software.
Here comes GNU ease.js.
2013-12-20 01:00:35 -05:00
|
|
|
* terms of the GNU General Public License as published by the Free Software
|
|
|
|
* Foundation, either version 3 of the License, or (at your option) any later
|
|
|
|
* version.
|
2010-12-20 19:13:27 -05:00
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
Relicensed under the GPLv3+
This project was originally LGPLv+-licensed to encourage its use in a community
that is largely copyleft-phobic. After further reflection, that was a mistake,
as adoption is not the important factor here---software freedom is.
When submitting ease.js to the GNU project, it was asked if I would be willing
to relicense it under the GPLv3+; I agreed happily, because there is no reason
why we should provide proprietary software any sort of edge. Indeed, proprietary
JavaScript is a huge problem since it is automatically downloaded on the user's
PC generally without them even knowing, and is a current focus for the FSF. As
such, to remain firm in our stance against proprietary JavaScript, relicensing
made the most sense for GNU.
This is likely to upset current users of ease.js. I am not sure of their
number---I have only seen download counts periodically on npmjs.org---but I know
there are at least a small number. These users are free to continue using the
previous LGPL'd releases, but with the understanding that there will be no
further maintenance (not even bug fixes). If possible, users should use the
GPL-licensed versions and release their software as free software.
Here comes GNU ease.js.
2013-12-20 01:00:35 -05:00
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
|
|
* more details.
|
2010-12-20 19:13:27 -05:00
|
|
|
*
|
Relicensed under the GPLv3+
This project was originally LGPLv+-licensed to encourage its use in a community
that is largely copyleft-phobic. After further reflection, that was a mistake,
as adoption is not the important factor here---software freedom is.
When submitting ease.js to the GNU project, it was asked if I would be willing
to relicense it under the GPLv3+; I agreed happily, because there is no reason
why we should provide proprietary software any sort of edge. Indeed, proprietary
JavaScript is a huge problem since it is automatically downloaded on the user's
PC generally without them even knowing, and is a current focus for the FSF. As
such, to remain firm in our stance against proprietary JavaScript, relicensing
made the most sense for GNU.
This is likely to upset current users of ease.js. I am not sure of their
number---I have only seen download counts periodically on npmjs.org---but I know
there are at least a small number. These users are free to continue using the
previous LGPL'd releases, but with the understanding that there will be no
further maintenance (not even bug fixes). If possible, users should use the
GPL-licensed versions and release their software as free software.
Here comes GNU ease.js.
2013-12-20 01:00:35 -05:00
|
|
|
* You should have received a copy of the GNU General Public License along with
|
|
|
|
* this program. If not, see <http://www.gnu.org/licenses/>.
|
2010-12-20 19:13:27 -05:00
|
|
|
*
|
|
|
|
* @author Mike Gerwitz
|
|
|
|
*/
|
|
|
|
|
2010-12-21 23:25:12 -05:00
|
|
|
var common = require( './common' ),
|
|
|
|
assert = require( 'assert' ),
|
|
|
|
util = common.require( 'util' );
|
2010-12-20 19:13:27 -05:00
|
|
|
|
|
|
|
var obj = {},
|
|
|
|
val = 'bar';
|
|
|
|
|
|
|
|
var expected = ( ( Object.defineProperty instanceof Function ) ? false : true ),
|
2011-03-07 09:03:03 -05:00
|
|
|
fallback = util.definePropertyFallback();
|
2010-12-20 19:13:27 -05:00
|
|
|
|
2010-12-28 13:45:33 -05:00
|
|
|
// IE 8 will fall back on first failure
|
|
|
|
if ( !expected && fallback )
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2011-03-07 09:03:03 -05:00
|
|
|
util.definePropertyFallback( false );
|
2010-12-28 13:45:33 -05:00
|
|
|
util.defineSecureProp( {}, 'foo', 1 );
|
|
|
|
|
|
|
|
// If the fallback was changed on us, then there was a problem (and this
|
|
|
|
// is likely IE8). Change the value we're expecting so our tests don't
|
|
|
|
// fail.
|
2011-03-07 09:03:03 -05:00
|
|
|
if ( util.definePropertyFallback() === true )
|
2010-12-28 13:45:33 -05:00
|
|
|
{
|
|
|
|
expected = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch ( e ) {}
|
|
|
|
}
|
|
|
|
|
2010-12-20 19:13:27 -05:00
|
|
|
assert.equal(
|
|
|
|
expected,
|
|
|
|
fallback,
|
2011-03-07 09:03:03 -05:00
|
|
|
"util.definePropertyFallback() returns whether defining a secure property is " +
|
2010-12-20 19:13:27 -05:00
|
|
|
"unsupported"
|
|
|
|
);
|
|
|
|
|
|
|
|
assert.equal(
|
2011-03-07 09:03:03 -05:00
|
|
|
util.definePropertyFallback( fallback ),
|
2010-12-20 19:13:27 -05:00
|
|
|
util,
|
2011-03-07 09:03:03 -05:00
|
|
|
"util.definePropertyFallback() returns self when used as a setter"
|
2010-12-20 19:13:27 -05:00
|
|
|
);
|
|
|
|
|
|
|
|
// perform secure property tests only if our parser supports it
|
|
|
|
if ( fallback === false )
|
|
|
|
{
|
|
|
|
util.defineSecureProp( obj, 'foo', val );
|
|
|
|
|
|
|
|
assert.equal(
|
|
|
|
obj.foo,
|
|
|
|
val,
|
|
|
|
"Defining a secure prop creates a property with the correct value on " +
|
|
|
|
"the given object"
|
|
|
|
);
|
|
|
|
|
|
|
|
// Our assertions below are going to use the data from the following method.
|
|
|
|
// We're not going to test directly whether they're writable, etc, because
|
|
|
|
// different engines may have different interpretations at this stage. (Or
|
|
|
|
// it may not yet be implemented.) Therefore, we'll simply see if what we
|
|
|
|
// requested has been set, and leave the problems up to the engine
|
|
|
|
// developers.
|
|
|
|
//
|
|
|
|
// This is a case of ensuring we're testing our own functionality. We do not
|
|
|
|
// want to test engine functionality.
|
|
|
|
var desc = Object.getOwnPropertyDescriptor( obj, 'foo' );
|
|
|
|
|
|
|
|
assert.equal(
|
|
|
|
desc.writable,
|
|
|
|
false,
|
|
|
|
"Secure property is not writable"
|
|
|
|
);
|
|
|
|
|
|
|
|
assert.equal(
|
|
|
|
desc.configurable,
|
|
|
|
false,
|
|
|
|
"Secure property is not configurable"
|
|
|
|
);
|
|
|
|
|
|
|
|
assert.equal(
|
|
|
|
desc.enumerable,
|
|
|
|
false,
|
|
|
|
"Secure property is not enumerable"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// be naughty so we can test the alternative implementation
|
2011-03-07 09:03:03 -05:00
|
|
|
util.definePropertyFallback( true );
|
2010-12-20 19:13:27 -05:00
|
|
|
|
|
|
|
var obj2 = {},
|
|
|
|
val2 = 'baz';
|
|
|
|
|
|
|
|
// this should fall back on defining a normal property
|
|
|
|
util.defineSecureProp( obj2, 'foo', val2 );
|
|
|
|
|
|
|
|
assert.equal(
|
|
|
|
obj2.foo,
|
|
|
|
val2,
|
|
|
|
"Secure property fallback still creates a property with the correct " +
|
|
|
|
"value on the given object"
|
|
|
|
);
|
|
|
|
|
|
|
|
// if we have the ES5 functions available, ensure that the property was not
|
|
|
|
// defined securely
|
|
|
|
if ( fallback === false )
|
|
|
|
{
|
|
|
|
var desc2 = Object.getOwnPropertyDescriptor( obj2, 'foo' );
|
|
|
|
|
|
|
|
assert.equal(
|
|
|
|
desc2.writable,
|
|
|
|
true,
|
|
|
|
"Secure property is writable when falling back"
|
|
|
|
);
|
|
|
|
|
|
|
|
assert.equal(
|
|
|
|
desc2.configurable,
|
|
|
|
true,
|
|
|
|
"Secure property is configurable when falling back"
|
|
|
|
);
|
|
|
|
|
|
|
|
assert.equal(
|
|
|
|
desc2.enumerable,
|
|
|
|
true,
|
|
|
|
"Secure property is enumerable when falling back"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
// restore in case the tests are not being run in separate processes
|
2011-03-07 09:03:03 -05:00
|
|
|
util.definePropertyFallback( fallback );
|
2010-12-20 19:13:27 -05:00
|
|
|
|