OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 js_backend; | 5 part of js_backend; |
6 | 6 |
7 class CodeEmitterNoEvalTask extends CodeEmitterTask { | 7 class CodeEmitterNoEvalTask extends CodeEmitterTask { |
8 CodeEmitterNoEvalTask(Compiler compiler, | 8 CodeEmitterNoEvalTask(Compiler compiler, |
9 Namer namer, | 9 Namer namer, |
10 bool generateSourceMap) | 10 bool generateSourceMap) |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 builder.addProperty('', buildUnusedConstructor(constructorName)); | 60 builder.addProperty('', buildUnusedConstructor(constructorName)); |
61 } else { | 61 } else { |
62 builder.addProperty('', buildConstructor(constructorName, fields)); | 62 builder.addProperty('', buildConstructor(constructorName, fields)); |
63 } | 63 } |
64 } | 64 } |
65 | 65 |
66 List get defineClassFunction { | 66 List get defineClassFunction { |
67 return [new jsAst.FunctionDeclaration( | 67 return [new jsAst.FunctionDeclaration( |
68 new jsAst.VariableDeclaration('defineClass'), | 68 new jsAst.VariableDeclaration('defineClass'), |
69 js.fun(['cls', 'constructor', 'prototype'], | 69 js.fun(['cls', 'constructor', 'prototype'], |
70 [js[r'constructor.prototype = prototype'], | 70 [js(r'constructor.prototype = prototype'), |
71 js[r'constructor.builtin$cls = cls'], | 71 js(r'constructor.builtin$cls = cls'), |
72 js.return_('constructor')]))]; | 72 js.return_('constructor')]))]; |
73 } | 73 } |
74 | 74 |
75 List buildProtoSupportCheck() { | 75 List buildProtoSupportCheck() { |
76 // We don't modify the prototypes in CSP mode. Therefore we can have an | 76 // We don't modify the prototypes in CSP mode. Therefore we can have an |
77 // easier prototype-check. | 77 // easier prototype-check. |
78 return [js['var $supportsProtoName = !(!({}.__proto__))']]; | 78 return [js('var $supportsProtoName = !(!({}.__proto__))')]; |
79 } | 79 } |
80 | 80 |
81 jsAst.Expression buildConstructor(String mangledName, | 81 jsAst.Expression buildConstructor(String mangledName, |
82 List<String> fieldNames) { | 82 List<String> fieldNames) { |
83 return new jsAst.NamedFunction( | 83 return new jsAst.NamedFunction( |
84 new jsAst.VariableDeclaration(mangledName), | 84 new jsAst.VariableDeclaration(mangledName), |
85 js.fun(fieldNames, fieldNames.map( | 85 js.fun(fieldNames, fieldNames.map( |
86 (name) => js['this.$name = $name']).toList())); | 86 (name) => js('this.$name = $name')).toList())); |
87 } | 87 } |
88 | 88 |
89 jsAst.Expression buildUnusedConstructor(String mangledName) { | 89 jsAst.Expression buildUnusedConstructor(String mangledName) { |
90 String message = 'Called unused constructor'; | 90 String message = 'Called unused constructor'; |
91 return new jsAst.NamedFunction( | 91 return new jsAst.NamedFunction( |
92 new jsAst.VariableDeclaration(mangledName), | 92 new jsAst.VariableDeclaration(mangledName), |
93 js.fun([], new jsAst.Throw(js.string(message)))); | 93 js.fun([], new jsAst.Throw(js.string(message)))); |
94 } | 94 } |
95 | 95 |
96 jsAst.FunctionDeclaration get generateAccessorFunction { | 96 jsAst.FunctionDeclaration get generateAccessorFunction { |
97 String message = | 97 String message = |
98 'Internal error: no dynamic generation of accessors allowed.'; | 98 'Internal error: no dynamic generation of accessors allowed.'; |
99 return new jsAst.FunctionDeclaration( | 99 return new jsAst.FunctionDeclaration( |
100 new jsAst.VariableDeclaration('generateAccessor'), | 100 new jsAst.VariableDeclaration('generateAccessor'), |
101 js.fun([], new jsAst.Throw(js.string(message)))); | 101 js.fun([], new jsAst.Throw(js.string(message)))); |
102 } | 102 } |
103 | 103 |
104 jsAst.Expression buildLazyInitializedGetter(VariableElement element) { | 104 jsAst.Expression buildLazyInitializedGetter(VariableElement element) { |
105 String isolate = namer.CURRENT_ISOLATE; | 105 String isolate = namer.CURRENT_ISOLATE; |
106 String name = namer.getName(element); | 106 String name = namer.getName(element); |
107 return js.fun([], js.return_(js['$isolate.$name'])); | 107 return js.fun([], js.return_(js('$isolate.$name'))); |
108 } | 108 } |
109 | 109 |
110 jsAst.Fun get lazyInitializerFunction { | 110 jsAst.Fun get lazyInitializerFunction { |
111 // function(prototype, staticName, fieldName, | 111 // function(prototype, staticName, fieldName, |
112 // getterName, lazyValue, getter) { | 112 // getterName, lazyValue, getter) { |
113 var parameters = <String>['prototype', 'staticName', 'fieldName', | 113 var parameters = <String>['prototype', 'staticName', 'fieldName', |
114 'getterName', 'lazyValue', 'getter']; | 114 'getterName', 'lazyValue', 'getter']; |
115 return js.fun(parameters, addLazyInitializerLogic()); | 115 return js.fun(parameters, addLazyInitializerLogic()); |
116 } | 116 } |
117 | 117 |
118 jsAst.Fun get finishIsolateConstructorFunction { | 118 jsAst.Fun get finishIsolateConstructorFunction { |
119 // We replace the old Isolate function with a new one that initializes | 119 // We replace the old Isolate function with a new one that initializes |
120 // all its fields with the initial (and often final) value of all globals. | 120 // all its fields with the initial (and often final) value of all globals. |
121 // | 121 // |
122 // We also copy over old values like the prototype, and the | 122 // We also copy over old values like the prototype, and the |
123 // isolateProperties themselves. | 123 // isolateProperties themselves. |
124 return js.fun('oldIsolate', [ | 124 return js.fun('oldIsolate', [ |
125 js['var isolateProperties = oldIsolate.${namer.isolatePropertiesName}'], | 125 js('var isolateProperties = oldIsolate.${namer.isolatePropertiesName}'), |
126 new jsAst.FunctionDeclaration( | 126 new jsAst.FunctionDeclaration( |
127 new jsAst.VariableDeclaration('Isolate'), | 127 new jsAst.VariableDeclaration('Isolate'), |
128 js.fun([], [ | 128 js.fun([], [ |
129 js['var hasOwnProperty = Object.prototype.hasOwnProperty'], | 129 js('var hasOwnProperty = Object.prototype.hasOwnProperty'), |
130 js.forIn('staticName', 'isolateProperties', | 130 js.forIn('staticName', 'isolateProperties', |
131 js.if_('hasOwnProperty.call(isolateProperties, staticName)', | 131 js.if_('hasOwnProperty.call(isolateProperties, staticName)', |
132 js['this[staticName] = isolateProperties[staticName]'])), | 132 js('this[staticName] = isolateProperties[staticName]'))), |
133 // Use the newly created object as prototype. In Chrome, | 133 // Use the newly created object as prototype. In Chrome, |
134 // this creates a hidden class for the object and makes | 134 // this creates a hidden class for the object and makes |
135 // sure it is fast to access. | 135 // sure it is fast to access. |
136 new jsAst.FunctionDeclaration( | 136 new jsAst.FunctionDeclaration( |
137 new jsAst.VariableDeclaration('ForceEfficientMap'), | 137 new jsAst.VariableDeclaration('ForceEfficientMap'), |
138 js.fun([], [])), | 138 js.fun([], [])), |
139 js['ForceEfficientMap.prototype = this'], | 139 js('ForceEfficientMap.prototype = this'), |
140 js['new ForceEfficientMap()']])), | 140 js('new ForceEfficientMap()')])), |
141 js['Isolate.prototype = oldIsolate.prototype'], | 141 js('Isolate.prototype = oldIsolate.prototype'), |
142 js['Isolate.prototype.constructor = Isolate'], | 142 js('Isolate.prototype.constructor = Isolate'), |
143 js['Isolate.${namer.isolatePropertiesName} = isolateProperties'], | 143 js('Isolate.${namer.isolatePropertiesName} = isolateProperties'), |
144 js.return_('Isolate')]); | 144 js.return_('Isolate')]); |
145 } | 145 } |
146 } | 146 } |
OLD | NEW |