Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(139)

Side by Side Diff: pkg/compiler/lib/src/js_emitter/old_emitter/reflection_data_parser.dart

Issue 833623003: dart2js: Merge intercepted names map. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: replace TODO with comment. Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 f = tearOff(funcs, array, isStatic, name, isIntercepted); 243 f = tearOff(funcs, array, isStatic, name, isIntercepted);
244 descriptor[name].\$getter = f; 244 descriptor[name].\$getter = f;
245 f.\$getterStub = true; 245 f.\$getterStub = true;
246 // Used to create an isolate using spawnFunction. 246 // Used to create an isolate using spawnFunction.
247 if (isStatic) #globalFunctions[name] = f; 247 if (isStatic) #globalFunctions[name] = f;
248 originalDescriptor[getterStubName] = descriptor[getterStubName] = f; 248 originalDescriptor[getterStubName] = descriptor[getterStubName] = f;
249 funcs.push(f); 249 funcs.push(f);
250 if (getterStubName) functions.push(getterStubName); 250 if (getterStubName) functions.push(getterStubName);
251 f.\$stubName = getterStubName; 251 f.\$stubName = getterStubName;
252 f.\$callName = null; 252 f.\$callName = null;
253 if (isIntercepted) #interceptedNames[getterStubName] = true; 253 // Update the interceptedNames map (which only exists if `invokeOn` was
254 // enabled).
255 if (#enabledInvokeOn)
256 if (isIntercepted) #interceptedNames[getterStubName] = 1;
254 } 257 }
255 258
256 if (#usesMangledNames) { 259 if (#usesMangledNames) {
257 var isReflectable = array.length > unmangledNameIndex; 260 var isReflectable = array.length > unmangledNameIndex;
258 if (isReflectable) { 261 if (isReflectable) {
259 for (var i = 0; i < funcs.length; i++) { 262 for (var i = 0; i < funcs.length; i++) {
260 funcs[i].$reflectableField = 1; 263 funcs[i].$reflectableField = 1;
261 funcs[i].$reflectionInfoField = array; 264 funcs[i].$reflectionInfoField = array;
262 } 265 }
263 var mangledNames = isStatic ? #mangledGlobalNames : #mangledNames; 266 var mangledNames = isStatic ? #mangledGlobalNames : #mangledNames;
264 var unmangledName = ${readString("array", "unmangledNameIndex")}; 267 var unmangledName = ${readString("array", "unmangledNameIndex")};
265 // The function is either a getter, a setter, or a method. 268 // The function is either a getter, a setter, or a method.
266 // If it is a method, it might also have a tear-off closure. 269 // If it is a method, it might also have a tear-off closure.
267 // The unmangledName is the same as the getter-name. 270 // The unmangledName is the same as the getter-name.
268 var reflectionName = unmangledName; 271 var reflectionName = unmangledName;
269 if (getterStubName) mangledNames[getterStubName] = reflectionName; 272 if (getterStubName) mangledNames[getterStubName] = reflectionName;
270 if (isSetter) { 273 if (isSetter) {
271 reflectionName += "="; 274 reflectionName += "=";
272 } else if (!isGetter) { 275 } else if (!isGetter) {
273 reflectionName += ":" + requiredParameterCount + 276 reflectionName += ":" + requiredParameterCount +
274 ":" + optionalParameterCount; 277 ":" + optionalParameterCount;
275 } 278 }
276 mangledNames[name] = reflectionName; 279 mangledNames[name] = reflectionName;
277 funcs[0].$reflectionNameField = reflectionName; 280 funcs[0].$reflectionNameField = reflectionName;
278 funcs[0].$metadataIndexField = unmangledNameIndex + 1; 281 funcs[0].$metadataIndexField = unmangledNameIndex + 1;
279 if (optionalParameterCount) descriptor[unmangledName + "*"] = funcs[0]; 282 if (optionalParameterCount) descriptor[unmangledName + "*"] = funcs[0];
280 } 283 }
281 } 284 }
282 } 285 }
283 ''', {'globalFunctions' : globalFunctionsAccess, 286 ''', {'globalFunctions': globalFunctionsAccess,
287 'enabledInvokeOn': compiler.enabledInvokeOn,
284 'interceptedNames': interceptedNamesAccess, 288 'interceptedNames': interceptedNamesAccess,
285 'usesMangledNames': 289 'usesMangledNames':
286 compiler.mirrorsLibrary != null || compiler.enabledFunctionApply, 290 compiler.mirrorsLibrary != null || compiler.enabledFunctionApply,
287 'mangledGlobalNames': mangledGlobalNamesAccess, 291 'mangledGlobalNames': mangledGlobalNamesAccess,
288 'mangledNames': mangledNamesAccess}); 292 'mangledNames': mangledNamesAccess});
289 293
290 List<jsAst.Statement> tearOffCode = buildTearOffCode(backend); 294 List<jsAst.Statement> tearOffCode = buildTearOffCode(backend);
291 295
296 jsAst.ObjectInitializer interceptedNamesSet =
297 oldEmitter.interceptorEmitter.generateInterceptedNamesSet();
298
292 jsAst.Statement init = js.statement('''{ 299 jsAst.Statement init = js.statement('''{
293 var functionCounter = 0; 300 var functionCounter = 0;
294 if (!#libraries) #libraries = []; 301 if (!#libraries) #libraries = [];
295 if (!#mangledNames) #mangledNames = map(); 302 if (!#mangledNames) #mangledNames = map();
296 if (!#mangledGlobalNames) #mangledGlobalNames = map(); 303 if (!#mangledGlobalNames) #mangledGlobalNames = map();
297 if (!#statics) #statics = map(); 304 if (!#statics) #statics = map();
298 if (!#typeInformation) #typeInformation = map(); 305 if (!#typeInformation) #typeInformation = map();
299 if (!#globalFunctions) #globalFunctions = map(); 306 if (!#globalFunctions) #globalFunctions = map();
300 if (!#interceptedNames) #interceptedNames = map(); 307 if (#enabledInvokeOn)
308 if (!#interceptedNames) #interceptedNames = #interceptedNamesSet;
301 var libraries = #libraries; 309 var libraries = #libraries;
302 var mangledNames = #mangledNames; 310 var mangledNames = #mangledNames;
303 var mangledGlobalNames = #mangledGlobalNames; 311 var mangledGlobalNames = #mangledGlobalNames;
304 var hasOwnProperty = Object.prototype.hasOwnProperty; 312 var hasOwnProperty = Object.prototype.hasOwnProperty;
305 var length = reflectionData.length; 313 var length = reflectionData.length;
306 var processedClasses = Object.create(null); 314 var processedClasses = Object.create(null);
307 processedClasses.collected = Object.create(null); 315 processedClasses.collected = Object.create(null);
308 processedClasses.pending = Object.create(null); 316 processedClasses.pending = Object.create(null);
309 if (#notInCspMode) { 317 if (#notInCspMode) {
310 processedClasses.constructorsList = []; 318 processedClasses.constructorsList = [];
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 libraries.push([name, uri, classes, functions, metadata, fields, isRoot, 350 libraries.push([name, uri, classes, functions, metadata, fields, isRoot,
343 globalObject]); 351 globalObject]);
344 } 352 }
345 if (#needsClassSupport) finishClasses(processedClasses); 353 if (#needsClassSupport) finishClasses(processedClasses);
346 }''', {'libraries': librariesAccess, 354 }''', {'libraries': librariesAccess,
347 'mangledNames': mangledNamesAccess, 355 'mangledNames': mangledNamesAccess,
348 'mangledGlobalNames': mangledGlobalNamesAccess, 356 'mangledGlobalNames': mangledGlobalNamesAccess,
349 'statics': staticsAccess, 357 'statics': staticsAccess,
350 'typeInformation': typeInformationAccess, 358 'typeInformation': typeInformationAccess,
351 'globalFunctions': globalFunctionsAccess, 359 'globalFunctions': globalFunctionsAccess,
360 'enabledInvokeOn': compiler.enabledInvokeOn,
352 'interceptedNames': interceptedNamesAccess, 361 'interceptedNames': interceptedNamesAccess,
362 'interceptedNamesSet': interceptedNamesSet,
353 'notInCspMode': !compiler.useContentSecurityPolicy, 363 'notInCspMode': !compiler.useContentSecurityPolicy,
354 'needsClassSupport': oldEmitter.needsClassSupport}); 364 'needsClassSupport': oldEmitter.needsClassSupport});
355 365
356 jsAst.Expression allClassesAccess = 366 jsAst.Expression allClassesAccess =
357 emitter.generateEmbeddedGlobalAccess(embeddedNames.ALL_CLASSES); 367 emitter.generateEmbeddedGlobalAccess(embeddedNames.ALL_CLASSES);
358 368
359 String specProperty = '"${namer.nativeSpecProperty}"'; // "%" 369 String specProperty = '"${namer.nativeSpecProperty}"'; // "%"
360 370
361 // Class descriptions are collected in a JS object. 371 // Class descriptions are collected in a JS object.
362 // 'finishClasses' takes all collected descriptions and sets up 372 // 'finishClasses' takes all collected descriptions and sets up
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
574 (function() { 584 (function() {
575 var result = $array[$index]; 585 var result = $array[$index];
576 if ($check) { 586 if ($check) {
577 throw new Error( 587 throw new Error(
578 name + ": expected value of type \'$type\' at index " + ($index) + 588 name + ": expected value of type \'$type\' at index " + ($index) +
579 " but got " + (typeof result)); 589 " but got " + (typeof result));
580 } 590 }
581 return result; 591 return result;
582 })()'''; 592 })()''';
583 } 593 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698