Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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; | 5 part of dart2js.js_emitter; |
| 6 | 6 |
| 7 // TODO(ahe): Share these with js_helper.dart. | 7 // TODO(ahe): Share these with js_helper.dart. |
| 8 const FUNCTION_INDEX = 0; | 8 const FUNCTION_INDEX = 0; |
| 9 const NAME_INDEX = 1; | 9 const NAME_INDEX = 1; |
| 10 const CALL_NAME_INDEX = 2; | 10 const CALL_NAME_INDEX = 2; |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 75 if (!optionalMethods) { | 75 if (!optionalMethods) { |
| 76 newDesc.$methodsWithOptionalArgumentsField = optionalMethods={} | 76 newDesc.$methodsWithOptionalArgumentsField = optionalMethods={} |
| 77 } | 77 } |
| 78 optionalMethods[property] = previousProperty; | 78 optionalMethods[property] = previousProperty; |
| 79 } else { | 79 } else { |
| 80 var elem = descriptor[property]; | 80 var elem = descriptor[property]; |
| 81 if (property !== "${namer.classDescriptorProperty}" && | 81 if (property !== "${namer.classDescriptorProperty}" && |
| 82 elem != null && | 82 elem != null && |
| 83 elem.constructor === Array && | 83 elem.constructor === Array && |
| 84 property !== "<>") { | 84 property !== "<>") { |
| 85 addStubs(newDesc, elem, property, false, descriptor, []); | 85 addStubs(newDesc, elem, property, false, []); |
| 86 } else { | 86 } else { |
| 87 newDesc[previousProperty = property] = elem; | 87 newDesc[previousProperty = property] = elem; |
| 88 } | 88 } |
| 89 } | 89 } |
| 90 } | 90 } |
| 91 | 91 |
| 92 /* The 'fields' are either a constructor function or a | 92 /* The 'fields' are either a constructor function or a |
| 93 * string encoding fields, constructor and superclass. Gets the | 93 * string encoding fields, constructor and superclass. Gets the |
| 94 * superclass and fields in the format | 94 * superclass and fields in the format |
| 95 * 'Super;field1,field2' | 95 * 'Super;field1,field2' |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 156 if (!optionalMethods) { | 156 if (!optionalMethods) { |
| 157 descriptor.$methodsWithOptionalArgumentsField = optionalMethods = {} | 157 descriptor.$methodsWithOptionalArgumentsField = optionalMethods = {} |
| 158 } | 158 } |
| 159 optionalMethods[property] = previousProperty; | 159 optionalMethods[property] = previousProperty; |
| 160 } else if (typeof element === "function") { | 160 } else if (typeof element === "function") { |
| 161 globalObject[previousProperty = property] = element; | 161 globalObject[previousProperty = property] = element; |
| 162 functions.push(property); | 162 functions.push(property); |
| 163 #globalFunctions[property] = element; | 163 #globalFunctions[property] = element; |
| 164 } else if (element.constructor === Array) { | 164 } else if (element.constructor === Array) { |
| 165 if (#needsStructuredMemberInfo) { | 165 if (#needsStructuredMemberInfo) { |
| 166 addStubs(globalObject, element, property, | 166 addStubs(globalObject, element, property, true, functions); |
| 167 true, descriptor, functions); | |
| 168 } | 167 } |
| 169 } else { | 168 } else { |
| 170 // We will not enter this case if no classes are defined. | 169 // We will not enter this case if no classes are defined. |
| 171 if (#hasClasses) { | 170 if (#hasClasses) { |
| 172 previousProperty = property; | 171 previousProperty = property; |
| 173 processClassData(property, element, processedClasses); | 172 processClassData(property, element, processedClasses); |
| 174 } | 173 } |
| 175 } | 174 } |
| 176 } | 175 } |
| 177 } | 176 } |
| 178 ''', {'typeInformation': typeInformationAccess, | 177 ''', {'typeInformation': typeInformationAccess, |
| 179 'globalFunctions': globalFunctionsAccess, | 178 'globalFunctions': globalFunctionsAccess, |
| 180 'hasClasses': oldEmitter.needsClassSupport, | 179 'hasClasses': oldEmitter.needsClassSupport, |
| 181 'needsStructuredMemberInfo': oldEmitter.needsStructuredMemberInfo}); | 180 'needsStructuredMemberInfo': oldEmitter.needsStructuredMemberInfo}); |
| 182 | 181 |
| 183 | 182 |
| 184 /** | 183 /** |
| 185 * See [dart2js.js_emitter.ContainerBuilder.addMemberMethod] for format of | 184 * See [dart2js.js_emitter.ContainerBuilder.addMemberMethod] for format of |
| 186 * [array]. | 185 * [array]. |
| 187 */ | 186 */ |
| 188 jsAst.Statement addStubs = js.statement(''' | 187 jsAst.Statement addStubs = js.statement(''' |
| 189 function addStubs(descriptor, array, name, isStatic, | 188 function addStubs(descriptor, array, name, isStatic, functions) { |
|
floitsch
2015/02/26 13:02:54
while you are at it...
imho descriptor is a reall
herhut
2015/03/09 13:33:58
I will do this in a later CL to avoid loads of mer
| |
| 190 originalDescriptor, functions) { | |
| 191 var index = $FUNCTION_INDEX, alias = array[index], f; | 189 var index = $FUNCTION_INDEX, alias = array[index], f; |
| 192 if (typeof alias == "string") { | 190 if (typeof alias == "string") { |
| 193 f = array[++index]; | 191 f = array[++index]; |
| 194 } else { | 192 } else { |
| 195 f = alias; | 193 f = alias; |
| 196 alias = name; | 194 alias = name; |
| 197 } | 195 } |
| 198 var funcs = [originalDescriptor[name] = descriptor[name] = | 196 var funcs = [descriptor[name] = descriptor[alias] = f]; |
| 199 descriptor[alias] = f]; | |
| 200 f.\$stubName = name; | 197 f.\$stubName = name; |
| 201 functions.push(name); | 198 functions.push(name); |
| 202 for (; index < array.length; index += 2) { | 199 for (; index < array.length; index += 2) { |
| 203 f = array[index + 1]; | 200 f = array[index + 1]; |
| 204 if (typeof f != "function") break; | 201 if (typeof f != "function") break; |
| 205 f.\$stubName = ${readString("array", "index + 2")}; | 202 f.\$stubName = ${readString("array", "index + 2")}; |
| 206 funcs.push(f); | 203 funcs.push(f); |
| 207 if (f.\$stubName) { | 204 if (f.\$stubName) { |
| 208 originalDescriptor[f.\$stubName] = descriptor[f.\$stubName] = f; | 205 descriptor[f.\$stubName] = f; |
| 209 functions.push(f.\$stubName); | 206 functions.push(f.\$stubName); |
| 210 } | 207 } |
| 211 } | 208 } |
| 212 index++; | 209 index++; |
| 213 for (var i = 0; i < funcs.length; index++, i++) { | 210 for (var i = 0; i < funcs.length; index++, i++) { |
| 214 funcs[i].\$callName = ${readString("array", "index")}; | 211 funcs[i].\$callName = ${readString("array", "index")}; |
| 215 } | 212 } |
| 216 var getterStubName = ${readString("array", "index")}; | 213 var getterStubName = ${readString("array", "index")}; |
| 217 array = array.slice(++index); | 214 array = array.slice(++index); |
| 218 var requiredParameterInfo = ${readInt("array", "0")}; | 215 var requiredParameterInfo = ${readInt("array", "0")}; |
| 219 var requiredParameterCount = requiredParameterInfo >> 1; | 216 var requiredParameterCount = requiredParameterInfo >> 1; |
| 220 var isAccessor = (requiredParameterInfo & 1) === 1; | 217 var isAccessor = (requiredParameterInfo & 1) === 1; |
| 221 var isSetter = requiredParameterInfo === 3; | 218 var isSetter = requiredParameterInfo === 3; |
| 222 var isGetter = requiredParameterInfo === 1; | 219 var isGetter = requiredParameterInfo === 1; |
| 223 var optionalParameterInfo = ${readInt("array", "1")}; | 220 var optionalParameterInfo = ${readInt("array", "1")}; |
| 224 var optionalParameterCount = optionalParameterInfo >> 1; | 221 var optionalParameterCount = optionalParameterInfo >> 1; |
| 225 var optionalParametersAreNamed = (optionalParameterInfo & 1) === 1; | 222 var optionalParametersAreNamed = (optionalParameterInfo & 1) === 1; |
| 226 var isIntercepted = | 223 var isIntercepted = |
| 227 requiredParameterCount + optionalParameterCount != funcs[0].length; | 224 requiredParameterCount + optionalParameterCount != funcs[0].length; |
| 228 var functionTypeIndex = ${readFunctionType("array", "2")}; | 225 var functionTypeIndex = ${readFunctionType("array", "2")}; |
| 229 var unmangledNameIndex = $unmangledNameIndex; | 226 var unmangledNameIndex = $unmangledNameIndex; |
| 230 | 227 |
| 231 if (getterStubName) { | 228 if (getterStubName) { |
| 232 f = tearOff(funcs, array, isStatic, name, isIntercepted); | 229 f = tearOff(funcs, array, isStatic, name, isIntercepted); |
| 233 descriptor[name].\$getter = f; | 230 descriptor[name].\$getter = f; |
| 234 f.\$getterStub = true; | 231 f.\$getterStub = true; |
| 235 // Used to create an isolate using spawnFunction. | 232 // Used to create an isolate using spawnFunction. |
| 236 if (isStatic) #globalFunctions[name] = f; | 233 if (isStatic) #globalFunctions[name] = f; |
| 237 originalDescriptor[getterStubName] = descriptor[getterStubName] = f; | 234 descriptor[getterStubName] = f; |
| 238 funcs.push(f); | 235 funcs.push(f); |
| 239 if (getterStubName) functions.push(getterStubName); | 236 if (getterStubName) functions.push(getterStubName); |
| 240 f.\$stubName = getterStubName; | 237 f.\$stubName = getterStubName; |
| 241 f.\$callName = null; | 238 f.\$callName = null; |
| 242 // Update the interceptedNames map (which only exists if `invokeOn` was | 239 // Update the interceptedNames map (which only exists if `invokeOn` was |
| 243 // enabled). | 240 // enabled). |
| 244 if (#enabledInvokeOn) | 241 if (#enabledInvokeOn) |
| 245 if (isIntercepted) #interceptedNames[getterStubName] = 1; | 242 if (isIntercepted) #interceptedNames[getterStubName] = 1; |
| 246 } | 243 } |
| 247 | 244 |
| (...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 485 (function() { | 482 (function() { |
| 486 var result = $array[$index]; | 483 var result = $array[$index]; |
| 487 if ($check) { | 484 if ($check) { |
| 488 throw new Error( | 485 throw new Error( |
| 489 name + ": expected value of type \'$type\' at index " + ($index) + | 486 name + ": expected value of type \'$type\' at index " + ($index) + |
| 490 " but got " + (typeof result)); | 487 " but got " + (typeof result)); |
| 491 } | 488 } |
| 492 return result; | 489 return result; |
| 493 })()'''; | 490 })()'''; |
| 494 } | 491 } |
| OLD | NEW |