Ensure clone methods create maps and sets from other realms.

This commit is contained in:
John-David Dalton
2015-09-10 19:05:25 -07:00
parent e50734a6fb
commit 8e0011d07a
2 changed files with 86 additions and 47 deletions

View File

@@ -449,24 +449,29 @@
_.attempt(function() {
_.extend(_, require('vm').runInNewContext([
'(function() {',
' var object = {',
" '_arguments': (function() { return arguments; }(1, 2, 3)),",
" '_array': [1, 2, 3],",
" '_boolean': Object(false),",
" '_date': new Date,",
" '_errors': [new Error, new EvalError, new RangeError, new ReferenceError, new SyntaxError, new TypeError, new URIError],",
" '_function': function() {},",
" '_nan': NaN,",
" '_null': null,",
" '_number': Object(0),",
" '_object': { 'a': 1, 'b': 2, 'c': 3 },",
" '_regexp': /x/,",
" '_string': Object('a'),",
" '_undefined': undefined",
' var root = this;',
'',
' var object = {',
" '_arguments': (function() { return arguments; }(1, 2, 3)),",
" '_array': [1, 2, 3],",
" '_arrayBuffer': new (this.ArrayByffer || Object),",
" '_boolean': Object(false),",
" '_date': new Date,",
" '_errors': [new Error, new EvalError, new RangeError, new ReferenceError, new SyntaxError, new TypeError, new URIError],",
" '_function': function() {},",
" '_map': new (root.Map || Object),",
" '_nan': NaN,",
" '_null': null,",
" '_number': Object(0),",
" '_object': { 'a': 1, 'b': 2, 'c': 3 },",
" '_regexp': /x/,",
" '_set': new (root.Set || Object),",
" '_string': Object('a'),",
" '_undefined': undefined",
' };',
'',
" ['" + typedArrays.join("', '") + "'].forEach(function(type) {",
" var Ctor = Function('return typeof ' + type + \" != 'undefined' && \" + type)()",
" var Ctor = root[type]",
' if (Ctor) {',
" object['_' + type.toLowerCase()] = new Ctor(new ArrayBuffer(24));",
' }',
@@ -486,22 +491,26 @@
var idoc = (idoc = iframe.contentDocument || iframe.contentWindow).document || idoc;
idoc.write([
'<script>',
'var root = this;',
'',
'parent._._arguments = (function() { return arguments; }(1, 2, 3));',
'parent._._array = [1, 2, 3];',
'parent._._arrayBuffer = new (this.ArrayByffer || Object);',
'parent._._boolean = Object(false);',
'parent._._date = new Date;',
"parent._._element = document.createElement('div');",
'parent._._errors = [new Error, new EvalError, new RangeError, new ReferenceError, new SyntaxError, new TypeError, new URIError];',
'parent._._function = function() {};',
'parent._._map = new (this.Map || Object);',
'parent._._nan = NaN;',
'parent._._null = null;',
'parent._._number = Object(0);',
"parent._._object = { 'a': 1, 'b': 2, 'c': 3 };",
'parent._._regexp = /x/;',
'parent._._set = new (this.Set || Object);',
"parent._._string = Object('a');",
'parent._._undefined = undefined;',
'',
'var root = this;',
"parent._.each(['" + typedArrays.join("', '") + "'], function(type) {",
' var Ctor = root[type];',
' if (Ctor) {',