Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 part of dart2js.js_emitter.startup_emitter.model_emitter; | 5 part of dart2js.js_emitter.startup_emitter.model_emitter; |
| 6 | 6 |
| 7 /// The name of the property that stores the tear-off getter on a static | 7 /// The name of the property that stores the tear-off getter on a static |
| 8 /// function. | 8 /// function. |
| 9 /// | 9 /// |
| 10 /// This property is only used when isolates are used. | 10 /// This property is only used when isolates are used. |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 53 // we can use "global" names however we want. As long as we don't shadow | 53 // we can use "global" names however we want. As long as we don't shadow |
| 54 // JavaScript variables (like `Array`) we are free to chose whatever variable | 54 // JavaScript variables (like `Array`) we are free to chose whatever variable |
| 55 // names we want. Furthermore, the pretty-printer minifies local variables, thus | 55 // names we want. Furthermore, the pretty-printer minifies local variables, thus |
| 56 // reducing their size. | 56 // reducing their size. |
| 57 const String mainBoilerplate = ''' | 57 const String mainBoilerplate = ''' |
| 58 (function dartProgram() { | 58 (function dartProgram() { |
| 59 // Copies the own properties from [from] to [to]. | 59 // Copies the own properties from [from] to [to]. |
| 60 function copyProperties(from, to) { | 60 function copyProperties(from, to) { |
| 61 var keys = Object.keys(from); | 61 var keys = Object.keys(from); |
| 62 for (var i = 0; i < keys.length; i++) { | 62 for (var i = 0; i < keys.length; i++) { |
| 63 to[keys[i]] = from[keys[i]]; | 63 var key = keys[i]; |
| 64 to[key] = from[key]; | |
| 64 } | 65 } |
| 65 } | 66 } |
| 66 | 67 |
| 67 // Only use direct proto access to construct the prototype chain (instead of | 68 // Only use direct proto access to construct the prototype chain (instead of |
| 68 // copying properties) on platforms where we know it works well (Chrome / d8). | 69 // copying properties) on platforms where we know it works well (Chrome / d8). |
| 69 var supportsDirectProtoAccess = #directAccessTestExpression; | 70 var supportsDirectProtoAccess = #directAccessTestExpression; |
| 70 | 71 |
| 71 var functionsHaveName = (function() { | 72 var functionsHaveName = (function() { |
| 72 function t() {}; | 73 function t() {}; |
| 73 return (typeof t.name == 'string') | 74 return (typeof t.name == 'string') |
| 74 })(); | 75 })(); |
| 75 | 76 |
| 76 var isChrome = (typeof window != 'undefined') && | 77 var isChrome = (typeof window != 'undefined') && |
|
Siggi Cherem (dart-lang)
2017/05/17 17:57:40
I believe this was only used for updateHolders, ma
sra1
2017/05/18 00:33:53
Done.
| |
| 77 (typeof window.chrome != 'undefined'); | 78 (typeof window.chrome != 'undefined'); |
| 78 | 79 |
| 79 // Sets the name property of functions, if the JS engine doesn't set the name | 80 // Sets the name property of functions, if the JS engine doesn't set the name |
| 80 // itself. | 81 // itself. |
| 81 // As of 2015 only IE doesn't set the name. | 82 // As of 2015 only IE doesn't set the name. |
| 82 function setFunctionNamesIfNecessary(holders) { | 83 function setFunctionNamesIfNecessary(holders) { |
| 83 if (functionsHaveName) return; | 84 if (functionsHaveName) return; |
| 84 for (var i = 0; i < holders.length; i++) { | 85 for (var i = 0; i < holders.length; i++) { |
| 85 var holder = holders[i]; | 86 var holder = holders[i]; |
| 86 var keys = Object.keys(holder); | 87 var keys = Object.keys(holder); |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 268 // This relies on the fact that types are added *after* the tear-offs have | 269 // This relies on the fact that types are added *after* the tear-offs have |
| 269 // been installed. The tear-off function uses the types-length to figure | 270 // been installed. The tear-off function uses the types-length to figure |
| 270 // out at which offset its types are located. If the types were added earlier | 271 // out at which offset its types are located. If the types were added earlier |
| 271 // the offset would be wrong. | 272 // the offset would be wrong. |
| 272 types.push.apply(types, newTypes); | 273 types.push.apply(types, newTypes); |
| 273 } | 274 } |
| 274 | 275 |
| 275 // Updates the given holder with the properties of the [newHolder]. | 276 // Updates the given holder with the properties of the [newHolder]. |
| 276 // This function is used when a deferred fragment is initialized. | 277 // This function is used when a deferred fragment is initialized. |
| 277 function updateHolder(holder, newHolder) { | 278 function updateHolder(holder, newHolder) { |
| 278 // Firefox doesn't like when important objects have their prototype chain | 279 copyProperties(newHolder, holder); |
| 279 // updated. We therefore do this only on V8. | |
| 280 if (isChrome) { | |
| 281 var oldPrototype = holder.__proto__; | |
| 282 newHolder.__proto__ = oldPrototype; | |
| 283 holder.__proto__ = newHolder; | |
| 284 } else { | |
| 285 copyProperties(newHolder, holder); | |
| 286 } | |
| 287 return holder; | 280 return holder; |
| 288 } | 281 } |
| 289 | 282 |
| 290 // Every deferred hunk (i.e. fragment) is a function that we can invoke to | 283 // Every deferred hunk (i.e. fragment) is a function that we can invoke to |
| 291 // initialize it. At this moment it contributes its data to the main hunk. | 284 // initialize it. At this moment it contributes its data to the main hunk. |
| 292 function initializeDeferredHunk(hunk) { | 285 function initializeDeferredHunk(hunk) { |
| 293 // Update the typesOffset for the next deferred library. | 286 // Update the typesOffset for the next deferred library. |
| 294 typesOffset = #embeddedTypes.length; | 287 typesOffset = #embeddedTypes.length; |
| 295 | 288 |
| 296 // TODO(floitsch): extend natives. | 289 // TODO(floitsch): extend natives. |
| (...skipping 1266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1563 } | 1556 } |
| 1564 statements.add(js.js.statement("setOrUpdateInterceptorsByTag(#);", | 1557 statements.add(js.js.statement("setOrUpdateInterceptorsByTag(#);", |
| 1565 js.objectLiteral(interceptorsByTag))); | 1558 js.objectLiteral(interceptorsByTag))); |
| 1566 statements.add( | 1559 statements.add( |
| 1567 js.js.statement("setOrUpdateLeafTags(#);", js.objectLiteral(leafTags))); | 1560 js.js.statement("setOrUpdateLeafTags(#);", js.objectLiteral(leafTags))); |
| 1568 statements.addAll(subclassAssignments); | 1561 statements.addAll(subclassAssignments); |
| 1569 | 1562 |
| 1570 return wrapPhase('nativeSupport', statements); | 1563 return wrapPhase('nativeSupport', statements); |
| 1571 } | 1564 } |
| 1572 } | 1565 } |
| OLD | NEW |