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) |
11 : super(compiler, namer, generateSourceMap); | 11 : super(compiler, namer, generateSourceMap); |
12 | 12 |
13 bool get getterAndSetterCanBeImplementedByFieldSpec => false; | 13 bool get getterAndSetterCanBeImplementedByFieldSpec => false; |
14 bool get generateTrivialNsmHandlers => false; | 14 bool get generateTrivialNsmHandlers => false; |
15 | 15 |
16 void emitSuper(String superName, ClassBuilder builder) { | 16 void emitSuper(String superName, ClassBuilder builder) { |
17 if (superName != '') { | 17 if (superName != '') { |
18 builder.addProperty('super', js.string(superName)); | 18 builder.addProperty('super', jsBuilder.string(superName)); |
19 } | 19 } |
20 } | 20 } |
21 | 21 |
22 void emitBoundClosureClassHeader(String mangledName, | 22 void emitBoundClosureClassHeader(String mangledName, |
23 String superName, | 23 String superName, |
24 List<String> fieldNames, | 24 List<String> fieldNames, |
25 ClassBuilder builder) { | 25 ClassBuilder builder) { |
26 builder.addProperty('', buildConstructor(mangledName, fieldNames)); | 26 builder.addProperty('', buildConstructor(mangledName, fieldNames)); |
27 emitSuper(superName, builder); | 27 emitSuper(superName, builder); |
28 } | 28 } |
(...skipping 30 matching lines...) Expand all Loading... |
59 if (classElement.isNative()) { | 59 if (classElement.isNative()) { |
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 jsBuilder.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 jsBuilder.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 jsBuilder.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 jsBuilder.fun([], new jsAst.Throw(jsBuilder.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 jsBuilder.fun([], new jsAst.Throw(jsBuilder.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 jsBuilder.fun([], jsBuilder.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 jsBuilder.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 jsBuilder.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 jsBuilder.fun([], [ |
129 js['var hasOwnProperty = Object.prototype.hasOwnProperty'], | 129 js('var hasOwnProperty = Object.prototype.hasOwnProperty'), |
130 js.forIn('staticName', 'isolateProperties', | 130 jsBuilder.forIn('staticName', 'isolateProperties', |
131 js.if_('hasOwnProperty.call(isolateProperties, staticName)', | 131 jsBuilder.if_( |
132 js['this[staticName] = isolateProperties[staticName]'])), | 132 'hasOwnProperty.call(isolateProperties, staticName)', |
| 133 js('this[staticName] = isolateProperties[staticName]'))), |
133 // Use the newly created object as prototype. In Chrome, | 134 // Use the newly created object as prototype. In Chrome, |
134 // this creates a hidden class for the object and makes | 135 // this creates a hidden class for the object and makes |
135 // sure it is fast to access. | 136 // sure it is fast to access. |
136 new jsAst.FunctionDeclaration( | 137 new jsAst.FunctionDeclaration( |
137 new jsAst.VariableDeclaration('ForceEfficientMap'), | 138 new jsAst.VariableDeclaration('ForceEfficientMap'), |
138 js.fun([], [])), | 139 jsBuilder.fun([], [])), |
139 js['ForceEfficientMap.prototype = this'], | 140 js('ForceEfficientMap.prototype = this'), |
140 js['new ForceEfficientMap()']])), | 141 js('new ForceEfficientMap()')])), |
141 js['Isolate.prototype = oldIsolate.prototype'], | 142 js('Isolate.prototype = oldIsolate.prototype'), |
142 js['Isolate.prototype.constructor = Isolate'], | 143 js('Isolate.prototype.constructor = Isolate'), |
143 js['Isolate.${namer.isolatePropertiesName} = isolateProperties'], | 144 js('Isolate.${namer.isolatePropertiesName} = isolateProperties'), |
144 js.return_('Isolate')]); | 145 jsBuilder.return_('Isolate')]); |
145 } | 146 } |
146 } | 147 } |
OLD | NEW |