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

Side by Side Diff: sdk/lib/_internal/compiler/implementation/js_emitter/reflection_data_parser.dart

Issue 416873002: Don't include class-static functions in library mirror. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fix typos. Created 6 years, 4 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 28 matching lines...) Expand all
39 39
40 String header = ''' 40 String header = '''
41 // [map] returns an object literal that V8 shouldn not try to optimize with a 41 // [map] returns an object literal that V8 shouldn not try to optimize with a
42 // hidden class. This prevents a potential performance problem where V8 tries 42 // hidden class. This prevents a potential performance problem where V8 tries
43 // to build a hidden class for an object used as a hashMap. 43 // to build a hidden class for an object used as a hashMap.
44 44
45 function map(x){x={x:x};delete x.x;return x} 45 function map(x){x={x:x};delete x.x;return x}
46 '''; 46 ''';
47 47
48 String processStatics = ''' 48 String processStatics = '''
49 function processStatics(descriptor) { 49 function processStatics(descriptor, isLibrary) {
50 for (var property in descriptor) { 50 for (var property in descriptor) {
51 if (!hasOwnProperty.call(descriptor, property)) continue; 51 if (!hasOwnProperty.call(descriptor, property)) continue;
52 if (property === "${namer.classDescriptorProperty}") continue; 52 if (property === "${namer.classDescriptorProperty}") continue;
53 var element = descriptor[property]; 53 var element = descriptor[property];
54 var firstChar = property.substring(0, 1); 54 var firstChar = property.substring(0, 1);
55 var previousProperty; 55 var previousProperty;
56 if (firstChar === "+") { 56 if (firstChar === "+") {
57 mangledGlobalNames[previousProperty] = property.substring(1); 57 mangledGlobalNames[previousProperty] = property.substring(1);
58 var flag = descriptor[property]; 58 var flag = descriptor[property];
59 if (flag > 0) 59 if (flag > 0)
60 descriptor[previousProperty].$reflectableField = flag; 60 descriptor[previousProperty].$reflectableField = flag;
61 if (element && element.length) 61 if (element && element.length)
62 init.typeInformation[previousProperty] = element; 62 init.typeInformation[previousProperty] = element;
63 } else if (firstChar === "@") { 63 } else if (firstChar === "@") {
64 property = property.substring(1); 64 property = property.substring(1);
65 ${namer.currentIsolate}[property][$metadataField] = element; 65 ${namer.currentIsolate}[property][$metadataField] = element;
66 } else if (firstChar === "*") { 66 } else if (firstChar === "*") {
67 globalObject[previousProperty].$defaultValuesField = element; 67 globalObject[previousProperty].$defaultValuesField = element;
68 var optionalMethods = descriptor.$methodsWithOptionalArgumentsField; 68 var optionalMethods = descriptor.$methodsWithOptionalArgumentsField;
69 if (!optionalMethods) { 69 if (!optionalMethods) {
70 descriptor.$methodsWithOptionalArgumentsField = optionalMethods = {} 70 descriptor.$methodsWithOptionalArgumentsField = optionalMethods = {}
71 } 71 }
72 optionalMethods[property] = previousProperty; 72 optionalMethods[property] = previousProperty;
73 } else if (typeof element === "function") { 73 } else if (typeof element === "function") {
74 globalObject[previousProperty = property] = element; 74 globalObject[previousProperty = property] = element;
75 functions.push(property); 75 if (isLibrary) functions.push(property);
76 init.globalFunctions[property] = element; 76 init.staticFunctions[property] = element;
77 } else if (element.constructor === Array) { 77 } else if (element.constructor === Array) {
78 addStubs(globalObject, element, property, 78 addStubs(globalObject, element, property,
79 true, descriptor, functions); 79 true, descriptor, isLibrary ? functions : []);
80 } else { 80 } else {
81 previousProperty = property; 81 previousProperty = property;
82 var newDesc = {}; 82 var newDesc = {};
83 var previousProp; 83 var previousProp;
84 for (var prop in element) { 84 for (var prop in element) {
85 if (!hasOwnProperty.call(element, prop)) continue; 85 if (!hasOwnProperty.call(element, prop)) continue;
86 firstChar = prop.substring(0, 1); 86 firstChar = prop.substring(0, 1);
87 if (prop === "static") { 87 if (prop === "static") {
88 processStatics(init.statics[property] = element[prop]); 88 processStatics(init.statics[property] = element[prop], false);
89 } else if (firstChar === "+") { 89 } else if (firstChar === "+") {
90 mangledNames[previousProp] = prop.substring(1); 90 mangledNames[previousProp] = prop.substring(1);
91 var flag = element[prop]; 91 var flag = element[prop];
92 if (flag > 0) 92 if (flag > 0)
93 element[previousProp].$reflectableField = flag; 93 element[previousProp].$reflectableField = flag;
94 } else if (firstChar === "@" && prop !== "@") { 94 } else if (firstChar === "@" && prop !== "@") {
95 newDesc[prop.substring(1)][$metadataField] = element[prop]; 95 newDesc[prop.substring(1)][$metadataField] = element[prop];
96 } else if (firstChar === "*") { 96 } else if (firstChar === "*") {
97 newDesc[previousProp].$defaultValuesField = element[prop]; 97 newDesc[previousProp].$defaultValuesField = element[prop];
98 var optionalMethods = newDesc.$methodsWithOptionalArgumentsField; 98 var optionalMethods = newDesc.$methodsWithOptionalArgumentsField;
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 requiredParameterCount + optionalParameterCount != funcs[0].length; 159 requiredParameterCount + optionalParameterCount != funcs[0].length;
160 var functionTypeIndex = ${readFunctionType("array", "2")}; 160 var functionTypeIndex = ${readFunctionType("array", "2")};
161 var unmangledNameIndex = $unmangledNameIndex; 161 var unmangledNameIndex = $unmangledNameIndex;
162 var isReflectable = array.length > unmangledNameIndex; 162 var isReflectable = array.length > unmangledNameIndex;
163 163
164 if (getterStubName) { 164 if (getterStubName) {
165 f = tearOff(funcs, array, isStatic, name, isIntercepted); 165 f = tearOff(funcs, array, isStatic, name, isIntercepted);
166 descriptor[name].\$getter = f; 166 descriptor[name].\$getter = f;
167 f.\$getterStub = true; 167 f.\$getterStub = true;
168 // Used to create an isolate using spawnFunction. 168 // Used to create an isolate using spawnFunction.
169 if (isStatic) init.globalFunctions[name] = f; 169 if (isStatic) init.staticFunctions[name] = f;
170 originalDescriptor[getterStubName] = descriptor[getterStubName] = f; 170 originalDescriptor[getterStubName] = descriptor[getterStubName] = f;
171 funcs.push(f); 171 funcs.push(f);
172 if (getterStubName) functions.push(getterStubName); 172 if (getterStubName) functions.push(getterStubName);
173 f.\$stubName = getterStubName; 173 f.\$stubName = getterStubName;
174 f.\$callName = null; 174 f.\$callName = null;
175 if (isIntercepted) init.interceptedNames[getterStubName] = true; 175 if (isIntercepted) init.interceptedNames[getterStubName] = true;
176 } 176 }
177 if (isReflectable) { 177 if (isReflectable) {
178 for (var i = 0; i < funcs.length; i++) { 178 for (var i = 0; i < funcs.length; i++) {
179 funcs[i].$reflectableField = 1; 179 funcs[i].$reflectableField = 1;
(...skipping 24 matching lines...) Expand all
204 204
205 String init = ''' 205 String init = '''
206 var functionCounter = 0; 206 var functionCounter = 0;
207 var tearOffGetter = (typeof dart_precompiled == "function") 207 var tearOffGetter = (typeof dart_precompiled == "function")
208 ? tearOffGetterCsp : tearOffGetterNoCsp; 208 ? tearOffGetterCsp : tearOffGetterNoCsp;
209 if (!init.libraries) init.libraries = []; 209 if (!init.libraries) init.libraries = [];
210 if (!init.mangledNames) init.mangledNames = map(); 210 if (!init.mangledNames) init.mangledNames = map();
211 if (!init.mangledGlobalNames) init.mangledGlobalNames = map(); 211 if (!init.mangledGlobalNames) init.mangledGlobalNames = map();
212 if (!init.statics) init.statics = map(); 212 if (!init.statics) init.statics = map();
213 if (!init.typeInformation) init.typeInformation = map(); 213 if (!init.typeInformation) init.typeInformation = map();
214 if (!init.globalFunctions) init.globalFunctions = map(); 214 // staticFunctions contains all static functions (global or not). This is used
215 // when spawning isolates.
216 if (!init.staticFunctions) init.staticFunctions = map();
ahe 2014/08/04 09:19:40 At first, this change put me off. Then I checked t
215 if (!init.interceptedNames) init.interceptedNames = map(); 217 if (!init.interceptedNames) init.interceptedNames = map();
216 var libraries = init.libraries; 218 var libraries = init.libraries;
217 var mangledNames = init.mangledNames; 219 var mangledNames = init.mangledNames;
218 var mangledGlobalNames = init.mangledGlobalNames; 220 var mangledGlobalNames = init.mangledGlobalNames;
219 var hasOwnProperty = Object.prototype.hasOwnProperty; 221 var hasOwnProperty = Object.prototype.hasOwnProperty;
220 var length = reflectionData.length; 222 var length = reflectionData.length;
221 for (var i = 0; i < length; i++) { 223 for (var i = 0; i < length; i++) {
222 var data = reflectionData[i]; 224 var data = reflectionData[i];
223 225
224 // [data] contains these elements: 226 // [data] contains these elements:
(...skipping 10 matching lines...) Expand all
235 var name = data[0]; 237 var name = data[0];
236 var uri = data[1]; 238 var uri = data[1];
237 var metadata = data[2]; 239 var metadata = data[2];
238 var globalObject = data[3]; 240 var globalObject = data[3];
239 var descriptor = data[4]; 241 var descriptor = data[4];
240 var isRoot = !!data[5]; 242 var isRoot = !!data[5];
241 var fields = descriptor && descriptor["${namer.classDescriptorProperty}"]; 243 var fields = descriptor && descriptor["${namer.classDescriptorProperty}"];
242 if (fields instanceof Array) fields = fields[0]; 244 if (fields instanceof Array) fields = fields[0];
243 var classes = []; 245 var classes = [];
244 var functions = []; 246 var functions = [];
245 processStatics(descriptor); 247 processStatics(descriptor, true);
246 libraries.push([name, uri, classes, functions, metadata, fields, isRoot, 248 libraries.push([name, uri, classes, functions, metadata, fields, isRoot,
247 globalObject]); 249 globalObject]);
248 } 250 }
249 '''; 251 ''';
250 252
251 return js(''' 253 return js('''
252 (function (reflectionData) { 254 (function (reflectionData) {
253 "use strict"; 255 "use strict";
254 $header 256 $header
255 $processStatics 257 $processStatics
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
374 (function() { 376 (function() {
375 var result = $array[$index]; 377 var result = $array[$index];
376 if ($check) { 378 if ($check) {
377 throw new Error( 379 throw new Error(
378 name + ": expected value of type \'$type\' at index " + ($index) + 380 name + ": expected value of type \'$type\' at index " + ($index) +
379 " but got " + (typeof result)); 381 " but got " + (typeof result));
380 } 382 }
381 return result; 383 return result;
382 })()'''; 384 })()''';
383 } 385 }
OLDNEW
« no previous file with comments | « no previous file | sdk/lib/_internal/lib/isolate_helper.dart » ('j') | tests/lib/mirrors/library_declarations2_test.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698