Skip to content
Browse files

fusejs: Add sandboxed Boolean constructor to Fusebox. [jddalton]

  • Loading branch information...
1 parent 9096de5 commit 75c5fa6c6ee642b8c63462266b3d89ecc7c309c8 @jdalton jdalton committed Jan 24, 2010
Showing with 21 additions and 4 deletions.
  1. +2 −0 CHANGELOG
  2. +19 −4 src/lang/fusebox.js
View
2 CHANGELOG
@@ -1,3 +1,5 @@
+* Add sandboxed Boolean constructor to Fusebox. [jddalton]
+
* Add a lot of comments to Fuse.Fusebox() and cleanup its codebase. [jddalton]
* Break Fuse.Object.prototype's relationship to other sandboxed natives for consistency across sandbox variations. [jddalton]
View
23 src/lang/fusebox.js
@@ -101,14 +101,15 @@
})(),
createFusebox = function() {
- var Array, Date, Function, Number, Object, RegExp, String,
+ var Array, Boolean, Date, Function, Number, Object, RegExp, String,
glSlice = global.Array.prototype.slice,
glFunction = global.Function,
instance = new Klass,
matchStrict = /^\s*(['"])use strict\1/,
sandbox = createSandbox(),
toString = global.Object.prototype.toString,
__Array = sandbox.Array,
+ __Boolean = sandbox.Boolean,
__Date = sandbox.Date,
__Function = sandbox.Function,
__Number = sandbox.Number,
@@ -129,6 +130,12 @@
return result;
};
+ Boolean = function Boolean(value) {
+ var result = new __Boolean(value);
+ result['__proto__'] = boolPlugin;
+ return result;
+ };
+
Date = function Date(year, month, date, hours, minutes, seconds, ms) {
var result;
if (this.constructor === Date) {
@@ -159,7 +166,7 @@
Object = function Object(value) {
if (value != null) {
switch (toString.call(value)) {
- case '[object Boolean]': return new Boolean(value);
+ case '[object Boolean]': return Boolean(value);
case '[object Number]': return Number(value);
case '[object String]': return String(value);
case '[object Array]':
@@ -205,6 +212,10 @@
return new __Array();
};
+ Boolean = function Boolean(value) {
+ return new __Boolean(value);
+ };
+
Date = function Date(year, month, date, hours, minutes, seconds, ms) {
if (this.constructor === Date) {
return arguments.length === 1
@@ -244,7 +255,7 @@
Object = function Object(value) {
if (value != null) {
switch (toString.call(value)) {
- case '[object Boolean]': return new Boolean(value);
+ case '[object Boolean]': return Boolean(value);
case '[object Number]': return Number(value);
case '[object String]': return String(value);
case '[object Array]':
@@ -266,6 +277,7 @@
// map native wrappers prototype to those of the sandboxed natives
Array.prototype = __Array.prototype;
+ Boolean.prototype = __Boolean.prototype;
Date.prototype = __Date.prototype;
Function.prototype = __Function.prototype;
Number.prototype = __Number.prototype;
@@ -277,6 +289,7 @@
/*----------------------------------------------------------------------*/
var arrPlugin = Array.plugin = Array.prototype,
+ boolPlugin = Boolean.plugin = Boolean.prototype,
datePlugin = Date.plugin = Date.prototype,
funcPlugin = Function.plugin = Function.prototype,
objPlugin = Object.plugin = Object.prototype,
@@ -732,6 +745,7 @@
// point constructor properties to the native wrappers
arrPlugin.constructor = Array;
+ boolPlugin.constructor = Boolean;
datePlugin.constructor = Date;
funcPlugin.constructor = Function;
objPlugin.constructor = Object;
@@ -759,6 +773,7 @@
// assign native wrappers to Fusebox instance and return
instance.Array = Array;
+ instance.Boolean = Boolean;
instance.Date = Date;
instance.Function = Function;
instance.Number = Number;
@@ -887,7 +902,7 @@
// alias
Fuse.List = Fuse.Array;
- })('Array', 'Date', 'Function', 'Number', 'Object', 'RegExp', 'String');
+ })('Array', 'Boolean', 'Date', 'Function', 'Number', 'Object', 'RegExp', 'String');
return Fusebox;
})();

0 comments on commit 75c5fa6

Please sign in to comment.
Something went wrong with that request. Please try again.