Merge branch 'master' into visibility/master
commit
960be880ab
|
@ -171,7 +171,17 @@ exports.buildProp = function( members, meta, name, value, keywords, cmp )
|
|||
*/
|
||||
exports.buildGetter = function( members, meta, name, value, keywords )
|
||||
{
|
||||
getMemberVisibility( members, keywords ).__defineGetter__( name, value );
|
||||
Object.defineProperty(
|
||||
getMemberVisibility( members, keywords ),
|
||||
name,
|
||||
{
|
||||
get: value,
|
||||
enumerable: true,
|
||||
|
||||
// otherwise we can't add a setter to this
|
||||
configurable: true,
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
|
@ -191,7 +201,17 @@ exports.buildGetter = function( members, meta, name, value, keywords )
|
|||
*/
|
||||
exports.buildSetter = function( members, meta, name, value, keywords )
|
||||
{
|
||||
getMemberVisibility( members, keywords ).__defineSetter__( name, value );
|
||||
Object.defineProperty(
|
||||
getMemberVisibility( members, keywords ),
|
||||
name,
|
||||
{
|
||||
set: value,
|
||||
enumerable: true,
|
||||
|
||||
// otherwise we can't add a getter to this
|
||||
configurable: true,
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
|
|
19
lib/util.js
19
lib/util.js
|
@ -25,15 +25,6 @@
|
|||
var propParseKeywords = require( './prop_parser' ).parseKeywords;
|
||||
|
||||
|
||||
/**
|
||||
* Whether getters/setters are supported
|
||||
* @var {boolean}
|
||||
*/
|
||||
var getset = ( Object.prototype.__defineGetter__ === undefined )
|
||||
? false
|
||||
: true
|
||||
;
|
||||
|
||||
/**
|
||||
* Whether we can actually define properties, or we need to fall back
|
||||
*
|
||||
|
@ -220,9 +211,15 @@ exports.propParse = function( data, options )
|
|||
continue;
|
||||
}
|
||||
|
||||
// retrieve getters/setters, if supported
|
||||
if ( can_define_prop )
|
||||
{
|
||||
var prop_desc = Object.getOwnPropertyDescriptor( data, prop );
|
||||
getter = prop_desc.get;
|
||||
setter = prop_desc.set;
|
||||
}
|
||||
|
||||
value = data[ prop ];
|
||||
getter = ( ( getset ) ? data.__lookupGetter__( prop ) : null );
|
||||
setter = ( ( getset ) ? data.__lookupSetter__( prop ) : null );
|
||||
|
||||
parse_data = keywordParser( prop ) || {};
|
||||
name = parse_data.name || prop;
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
{
|
||||
"name": "easejs",
|
||||
"description": "A basic collection of CommonJS modules intended to \"ease\" the transition into Javascript from other Object-Oriented languages",
|
||||
"version": "0.1.0-pre",
|
||||
"author": "Mike Gerwitz <mike@mikegerwitz.com>",
|
||||
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/mikegerwitz/easejs.git"
|
||||
},
|
||||
|
||||
"tags": [
|
||||
"object oriented",
|
||||
"oo",
|
||||
"util",
|
||||
"utility",
|
||||
"lib",
|
||||
"library",
|
||||
"framework",
|
||||
"classes",
|
||||
"interfaces",
|
||||
"protected members",
|
||||
"inheritance"
|
||||
]
|
||||
}
|
|
@ -22,46 +22,60 @@
|
|||
* @package test
|
||||
*/
|
||||
|
||||
// don't perform these tests if getters/setters are unsupported
|
||||
if ( Object.prototype.__defineGetter__ === undefined )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var common = require( './common' ),
|
||||
assert = require( 'assert' ),
|
||||
Class = common.require( 'class' ),
|
||||
util = common.require( 'util' ),
|
||||
|
||||
foo_def = {},
|
||||
sub_foo_def = {}
|
||||
;
|
||||
|
||||
// don't perform these tests if getters/setters are unsupported
|
||||
if ( util.definePropertyFallback() )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// to prevent syntax errors in browsers that do not support getters/setters in
|
||||
// object notation
|
||||
foo_def.__defineGetter__( 'foo', function ()
|
||||
Object.defineProperty( foo_def, 'foo', {
|
||||
get: function ()
|
||||
{
|
||||
return this._foo;
|
||||
} );
|
||||
foo_def.__defineSetter__( 'foo', function ( val )
|
||||
},
|
||||
set: function ( val )
|
||||
{
|
||||
this._foo = ''+( val );
|
||||
} );
|
||||
foo_def.__defineGetter__( 'bar', function ()
|
||||
{
|
||||
return 'durp';
|
||||
} );
|
||||
foo_def.__defineSetter__( 'bar', function ( val )
|
||||
{
|
||||
},
|
||||
|
||||
enumerable: true,
|
||||
} );
|
||||
|
||||
sub_foo_def.__defineGetter__( 'bar', function ()
|
||||
Object.defineProperty( foo_def, 'bar', {
|
||||
get: function ()
|
||||
{
|
||||
return 'durp';
|
||||
},
|
||||
set: function ( val )
|
||||
{
|
||||
},
|
||||
|
||||
enumerable: true,
|
||||
} );
|
||||
|
||||
Object.defineProperty( sub_foo_def, 'bar', {
|
||||
get: function ()
|
||||
{
|
||||
return this.bar2;
|
||||
} );
|
||||
sub_foo_def.__defineSetter__( 'bar', function ( val )
|
||||
},
|
||||
set: function ( val )
|
||||
{
|
||||
this.bar2 = val;
|
||||
},
|
||||
|
||||
enumerable: true,
|
||||
} );
|
||||
|
||||
var Foo = Class.extend( foo_def ),
|
||||
|
|
|
@ -24,7 +24,9 @@
|
|||
|
||||
var common = require( './common' ),
|
||||
assert = require( 'assert' ),
|
||||
Interface = common.require( 'interface' );
|
||||
Interface = common.require( 'interface' ),
|
||||
util = common.require( 'util' )
|
||||
;
|
||||
|
||||
|
||||
( function testPropertiesNotPermittedWithinInterfaces()
|
||||
|
@ -43,7 +45,7 @@ var common = require( './common' ),
|
|||
( function testGettersAndSettersNotPermittedWithinInterfaces()
|
||||
{
|
||||
// don't perform this test if unsupported by environment
|
||||
if ( Object.prototype.__defineGetter__ === undefined )
|
||||
if ( util.definePropertyFallback() )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
@ -51,8 +53,12 @@ var common = require( './common' ),
|
|||
// so we don't break browsers that do not support getters/setters in object
|
||||
// notation
|
||||
var data = {};
|
||||
data.__defineGetter__( 'foo', function() {} );
|
||||
data.__defineSetter__( 'foo', function() {} );
|
||||
Object.defineProperty( data, 'foo', {
|
||||
get: function() {},
|
||||
set: function() {},
|
||||
|
||||
enumerable: true,
|
||||
} );
|
||||
|
||||
assert.throws( function()
|
||||
{
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#!/bin/bash
|
||||
#!/bin/sh
|
||||
#
|
||||
# Copyright (C) 2010 Mike Gerwitz
|
||||
#
|
||||
|
|
|
@ -24,7 +24,8 @@
|
|||
|
||||
var common = require( './common' ),
|
||||
assert = require( 'assert' ),
|
||||
util = common.require( 'util' );
|
||||
util = common.require( 'util' )
|
||||
;
|
||||
|
||||
|
||||
( function testAbstractKeywordDesignatesMethodAsAbstract()
|
||||
|
@ -173,15 +174,19 @@ var common = require( './common' ),
|
|||
|
||||
|
||||
// for browsers that support it
|
||||
if ( Object.prototype.__defineGetter__ !== undefined )
|
||||
if ( util.definePropertyFallback() === false )
|
||||
{
|
||||
data = {};
|
||||
parsed_keywords = {};
|
||||
|
||||
// to prevent syntax errors for environments that don't support
|
||||
// getters/setters in object notation
|
||||
data.__defineGetter__( 'public foo', function() {} );
|
||||
data.__defineSetter__( 'public foo', function() {} );
|
||||
Object.defineProperty( data, 'public foo', {
|
||||
get: function() {},
|
||||
set: function() {},
|
||||
|
||||
enumerable: true,
|
||||
} );
|
||||
|
||||
|
||||
util.propParse( data, {
|
||||
|
|
|
@ -26,7 +26,7 @@ var common = require( './common' ),
|
|||
assert = require( 'assert' ),
|
||||
util = common.require( 'util' ),
|
||||
|
||||
get_set = ( ( Object.prototype.__defineGetter__ ) ? true : false )
|
||||
get_set = !( util.definePropertyFallback() )
|
||||
;
|
||||
|
||||
var data = {
|
||||
|
@ -52,8 +52,12 @@ var data = {
|
|||
// only add getter/setter if it's supported by our engine
|
||||
if ( get_set )
|
||||
{
|
||||
data.__defineGetter__( 'someFoo', function () {} );
|
||||
data.__defineSetter__( 'someFoo', function () {} );
|
||||
Object.defineProperty( data, 'someFoo', {
|
||||
get: function () {},
|
||||
set: function () {},
|
||||
|
||||
enumerable: true,
|
||||
} );
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#!/bin/bash
|
||||
#!/bin/sh
|
||||
#
|
||||
# Copyright (C) 2010 Mike Gerwitz
|
||||
#
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#!/bin/bash
|
||||
#!/bin/sh
|
||||
#
|
||||
# Removes trailing commas from array and object declarations (certain browsers,
|
||||
# such as earlier versions of IE, do not parse trailing commas correctly)
|
||||
|
|
Loading…
Reference in New Issue