1
0
Fork 0

Merge branch 'master' into visibility/master

closure/master
Mike Gerwitz 2011-03-07 23:09:02 -05:00
commit 960be880ab
10 changed files with 124 additions and 53 deletions

View File

@ -171,7 +171,17 @@ exports.buildProp = function( members, meta, name, value, keywords, cmp )
*/ */
exports.buildGetter = function( members, meta, name, value, keywords ) 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 ) 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,
}
);
}; };

View File

@ -25,15 +25,6 @@
var propParseKeywords = require( './prop_parser' ).parseKeywords; 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 * Whether we can actually define properties, or we need to fall back
* *
@ -220,9 +211,15 @@ exports.propParse = function( data, options )
continue; 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 ]; value = data[ prop ];
getter = ( ( getset ) ? data.__lookupGetter__( prop ) : null );
setter = ( ( getset ) ? data.__lookupSetter__( prop ) : null );
parse_data = keywordParser( prop ) || {}; parse_data = keywordParser( prop ) || {};
name = parse_data.name || prop; name = parse_data.name || prop;

25
package.json 100644
View File

@ -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"
]
}

View File

@ -22,46 +22,60 @@
* @package test * @package test
*/ */
// don't perform these tests if getters/setters are unsupported
if ( Object.prototype.__defineGetter__ === undefined )
{
return;
}
var common = require( './common' ), var common = require( './common' ),
assert = require( 'assert' ), assert = require( 'assert' ),
Class = common.require( 'class' ), Class = common.require( 'class' ),
util = common.require( 'util' ),
foo_def = {}, foo_def = {},
sub_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 // to prevent syntax errors in browsers that do not support getters/setters in
// object notation // object notation
foo_def.__defineGetter__( 'foo', function () Object.defineProperty( foo_def, 'foo', {
{ get: function ()
return this._foo; {
} ); return this._foo;
foo_def.__defineSetter__( 'foo', function ( val ) },
{ set: function ( val )
this._foo = ''+( val ); {
} ); this._foo = ''+( val );
foo_def.__defineGetter__( 'bar', function () },
{
return 'durp'; enumerable: true,
} );
foo_def.__defineSetter__( 'bar', function ( val )
{
} ); } );
sub_foo_def.__defineGetter__( 'bar', function () Object.defineProperty( foo_def, 'bar', {
{ get: function ()
return this.bar2; {
return 'durp';
},
set: function ( val )
{
},
enumerable: true,
} ); } );
sub_foo_def.__defineSetter__( 'bar', function ( val )
{ Object.defineProperty( sub_foo_def, 'bar', {
this.bar2 = val; get: function ()
{
return this.bar2;
},
set: function ( val )
{
this.bar2 = val;
},
enumerable: true,
} ); } );
var Foo = Class.extend( foo_def ), var Foo = Class.extend( foo_def ),

View File

@ -24,7 +24,9 @@
var common = require( './common' ), var common = require( './common' ),
assert = require( 'assert' ), assert = require( 'assert' ),
Interface = common.require( 'interface' ); Interface = common.require( 'interface' ),
util = common.require( 'util' )
;
( function testPropertiesNotPermittedWithinInterfaces() ( function testPropertiesNotPermittedWithinInterfaces()
@ -43,7 +45,7 @@ var common = require( './common' ),
( function testGettersAndSettersNotPermittedWithinInterfaces() ( function testGettersAndSettersNotPermittedWithinInterfaces()
{ {
// don't perform this test if unsupported by environment // don't perform this test if unsupported by environment
if ( Object.prototype.__defineGetter__ === undefined ) if ( util.definePropertyFallback() )
{ {
return; return;
} }
@ -51,8 +53,12 @@ var common = require( './common' ),
// so we don't break browsers that do not support getters/setters in object // so we don't break browsers that do not support getters/setters in object
// notation // notation
var data = {}; var data = {};
data.__defineGetter__( 'foo', function() {} ); Object.defineProperty( data, 'foo', {
data.__defineSetter__( 'foo', function() {} ); get: function() {},
set: function() {},
enumerable: true,
} );
assert.throws( function() assert.throws( function()
{ {

View File

@ -1,4 +1,4 @@
#!/bin/bash #!/bin/sh
# #
# Copyright (C) 2010 Mike Gerwitz # Copyright (C) 2010 Mike Gerwitz
# #

View File

@ -24,7 +24,8 @@
var common = require( './common' ), var common = require( './common' ),
assert = require( 'assert' ), assert = require( 'assert' ),
util = common.require( 'util' ); util = common.require( 'util' )
;
( function testAbstractKeywordDesignatesMethodAsAbstract() ( function testAbstractKeywordDesignatesMethodAsAbstract()
@ -173,15 +174,19 @@ var common = require( './common' ),
// for browsers that support it // for browsers that support it
if ( Object.prototype.__defineGetter__ !== undefined ) if ( util.definePropertyFallback() === false )
{ {
data = {}; data = {};
parsed_keywords = {}; parsed_keywords = {};
// to prevent syntax errors for environments that don't support // to prevent syntax errors for environments that don't support
// getters/setters in object notation // getters/setters in object notation
data.__defineGetter__( 'public foo', function() {} ); Object.defineProperty( data, 'public foo', {
data.__defineSetter__( 'public foo', function() {} ); get: function() {},
set: function() {},
enumerable: true,
} );
util.propParse( data, { util.propParse( data, {

View File

@ -26,7 +26,7 @@ var common = require( './common' ),
assert = require( 'assert' ), assert = require( 'assert' ),
util = common.require( 'util' ), util = common.require( 'util' ),
get_set = ( ( Object.prototype.__defineGetter__ ) ? true : false ) get_set = !( util.definePropertyFallback() )
; ;
var data = { var data = {
@ -52,8 +52,12 @@ var data = {
// only add getter/setter if it's supported by our engine // only add getter/setter if it's supported by our engine
if ( get_set ) if ( get_set )
{ {
data.__defineGetter__( 'someFoo', function () {} ); Object.defineProperty( data, 'someFoo', {
data.__defineSetter__( 'someFoo', function () {} ); get: function () {},
set: function () {},
enumerable: true,
} );
} }

View File

@ -1,4 +1,4 @@
#!/bin/bash #!/bin/sh
# #
# Copyright (C) 2010 Mike Gerwitz # Copyright (C) 2010 Mike Gerwitz
# #

View File

@ -1,4 +1,4 @@
#!/bin/bash #!/bin/sh
# #
# Removes trailing commas from array and object declarations (certain browsers, # Removes trailing commas from array and object declarations (certain browsers,
# such as earlier versions of IE, do not parse trailing commas correctly) # such as earlier versions of IE, do not parse trailing commas correctly)