Enable other realm tests for Node too.

This commit is contained in:
John-David Dalton
2013-11-14 08:30:34 -08:00
parent 919166212f
commit e7ffb80877

View File

@@ -183,11 +183,28 @@
/*--------------------------------------------------------------------------*/ /*--------------------------------------------------------------------------*/
// add object from iframe // add values from other realms
(function() { (function() {
if (!document) { try {
return; _.extend(_, require('vm').runInNewContext([
} '({',
"'_arguments': (function() { return arguments; }(1, 2, 3)),",
"'_array': [1, 2, 3],",
"'_boolean': new Boolean(false),",
"'_date': new Date,",
"'_function': function() {},",
"'_nan': NaN,",
"'_null': null,",
"'_number': new Number(0),",
"'_object': { 'a': 1, 'b': 2, 'c': 3 },",
"'_regexp': /x/,",
"'_string': new String('a'),",
"'_undefined': undefined,",
'})'
].join('\n')));
} catch(e) { }
if (!_._object && document) {
var iframe = document.createElement('iframe'); var iframe = document.createElement('iframe');
iframe.frameBorder = iframe.height = iframe.width = 0; iframe.frameBorder = iframe.height = iframe.width = 0;
body.appendChild(iframe); body.appendChild(iframe);
@@ -211,6 +228,7 @@
'<\/script>' '<\/script>'
].join('\n')); ].join('\n'));
idoc.close(); idoc.close();
}
}()); }());
// add web worker // add web worker
@@ -3134,7 +3152,7 @@
deepEqual(actual, expected); deepEqual(actual, expected);
}); });
test('should work with `arguments` objects from an iframe', 1, function() { test('should work with `arguments` objects from another realm', 1, function() {
if (_._object) { if (_._object) {
strictEqual(_.isArguments(_._arguments), true); strictEqual(_.isArguments(_._arguments), true);
} }
@@ -3174,7 +3192,7 @@
deepEqual(actual, expected); deepEqual(actual, expected);
}); });
test('should work with arrays from an iframe', 1, function() { test('should work with arrays from another realm', 1, function() {
if (_._object) { if (_._object) {
strictEqual(_.isArray(_._array), true); strictEqual(_.isArray(_._array), true);
} }
@@ -3217,7 +3235,7 @@
deepEqual(actual, expected); deepEqual(actual, expected);
}); });
test('should work with booleans from an iframe', 1, function() { test('should work with booleans from another realm', 1, function() {
if (_._object) { if (_._object) {
strictEqual(_.isBoolean(_._boolean), true); strictEqual(_.isBoolean(_._boolean), true);
} }
@@ -3257,7 +3275,7 @@
deepEqual(actual, expected); deepEqual(actual, expected);
}); });
test('should work with dates from an iframe', 1, function() { test('should work with dates from another realm', 1, function() {
if (_._object) { if (_._object) {
strictEqual(_.isDate(_._date), true); strictEqual(_.isDate(_._date), true);
} }
@@ -3283,8 +3301,8 @@
strictEqual(_.isElement({ 'nodeType': '001' }), false); strictEqual(_.isElement({ 'nodeType': '001' }), false);
}); });
test('should work with elements from an iframe', 1, function() { test('should work with elements from another realm', 1, function() {
if (_._object) { if (_._element) {
strictEqual(_.isElement(_._element), true); strictEqual(_.isElement(_._element), true);
} }
else { else {
@@ -3875,7 +3893,7 @@
strictEqual(_.isFinite('08'), true); strictEqual(_.isFinite('08'), true);
}); });
test('should work with numbers from an iframe', 1, function() { test('should work with numbers from another realm', 1, function() {
if (_._object) { if (_._object) {
strictEqual(_.isFinite(_._number), true); strictEqual(_.isFinite(_._number), true);
} }
@@ -3915,7 +3933,7 @@
deepEqual(actual, expected); deepEqual(actual, expected);
}); });
test('should work with functions from an iframe', 1, function() { test('should work with functions from another realm', 1, function() {
if (_._object) { if (_._object) {
strictEqual(_.isFunction(_._function), true); strictEqual(_.isFunction(_._function), true);
} }
@@ -3957,7 +3975,7 @@
deepEqual(actual, expected); deepEqual(actual, expected);
}); });
test('should work with NaNs from an iframe', 1, function() { test('should work with NaNs from another realm', 1, function() {
if (_._object) { if (_._object) {
strictEqual(_.isNaN(_._nan), true); strictEqual(_.isNaN(_._nan), true);
} }
@@ -3998,7 +4016,7 @@
deepEqual(actual, expected); deepEqual(actual, expected);
}); });
test('should work with nulls from an iframe', 1, function() { test('should work with nulls from another realm', 1, function() {
if (_._object) { if (_._object) {
strictEqual(_.isNull(_._null), true); strictEqual(_.isNull(_._null), true);
} }
@@ -4039,7 +4057,7 @@
deepEqual(actual, expected); deepEqual(actual, expected);
}); });
test('should work with numbers from an iframe', 1, function() { test('should work with numbers from another realm', 1, function() {
if (_._object) { if (_._object) {
strictEqual(_.isNumber(_._number), true); strictEqual(_.isNumber(_._number), true);
} }
@@ -4089,19 +4107,24 @@
deepEqual(actual, expected); deepEqual(actual, expected);
}); });
test('should work with objects from an iframe', 8, function() { test('should work with objects from another realm', 8, function() {
if (_._element) {
strictEqual(_.isObject(_._element), true);
}
else {
skipTest();
}
if (_._object) { if (_._object) {
strictEqual(_.isObject(_._object), true); strictEqual(_.isObject(_._object), true);
strictEqual(_.isObject(_._boolean), true); strictEqual(_.isObject(_._boolean), true);
strictEqual(_.isObject(_._date), true); strictEqual(_.isObject(_._date), true);
strictEqual(_.isObject(_._element), true);
strictEqual(_.isObject(_._function), true); strictEqual(_.isObject(_._function), true);
strictEqual(_.isObject(_._number), true); strictEqual(_.isObject(_._number), true);
strictEqual(_.isObject(_._regexp), true); strictEqual(_.isObject(_._regexp), true);
strictEqual(_.isObject(_._string), true); strictEqual(_.isObject(_._string), true);
} }
else { else {
skipTest(8); skipTest(7);
} }
}); });
@@ -4169,7 +4192,7 @@
deepEqual(actual, expected); deepEqual(actual, expected);
}); });
test('should work with objects from an iframe', 1, function() { test('should work with objects from another realm', 1, function() {
if (_._object) { if (_._object) {
strictEqual(_.isPlainObject(_._object), true); strictEqual(_.isPlainObject(_._object), true);
} }
@@ -4210,7 +4233,7 @@
deepEqual(actual, expected); deepEqual(actual, expected);
}); });
test('should work with regexes from an iframe', 1, function() { test('should work with regexes from another realm', 1, function() {
if (_._object) { if (_._object) {
strictEqual(_.isRegExp(_._regexp), true); strictEqual(_.isRegExp(_._regexp), true);
} }
@@ -4251,7 +4274,7 @@
deepEqual(actual, expected); deepEqual(actual, expected);
}); });
test('should work with strings from an iframe', 1, function() { test('should work with strings from another realm', 1, function() {
if (_._object) { if (_._object) {
strictEqual(_.isString(_._string), true); strictEqual(_.isString(_._string), true);
} }
@@ -4293,7 +4316,7 @@
deepEqual(actual, expected); deepEqual(actual, expected);
}); });
test('should work with `undefined` from an iframe', 1, function() { test('should work with `undefined` from another realm', 1, function() {
if (_._object) { if (_._object) {
strictEqual(_.isUndefined(_._undefined), true); strictEqual(_.isUndefined(_._undefined), true);
} }