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

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

Issue 829473003: dart2js: move native boilerplate code into a separate file. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Rebase 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
(Empty)
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
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.
4
5 part of dart2js.js_emitter;
6
7 class NativeGenerator {
8 final Function generateEmbeddedGlobalAccess;
9
10 NativeGenerator(this.generateEmbeddedGlobalAccess);
11
12 /**
13 * Emits code that sets the `isolateTag embedded global to a unique string.
14 */
15 jsAst.Expression generateIsolateAffinityTagInitialization() {
16 jsAst.Expression getIsolateTagAccess =
17 generateEmbeddedGlobalAccess(embeddedNames.GET_ISOLATE_TAG);
18 jsAst.Expression isolateTagAccess =
19 generateEmbeddedGlobalAccess(embeddedNames.ISOLATE_TAG);
20
21 return js('''
22 !function() {
23 // On V8, the 'intern' function converts a string to a symbol, which
24 // makes property access much faster.
25 function intern(s) {
26 var o = {};
27 o[s] = 1;
28 return Object.keys(convertToFastObject(o))[0];
29 }
30
31 #getIsolateTag = function(name) {
32 return intern("___dart_" + name + #isolateTag);
33 };
34
35 // To ensure that different programs loaded into the same context (page)
36 // use distinct dispatch properies, we place an object on `Object` to
37 // contain the names already in use.
38 var tableProperty = "___dart_isolate_tags_";
39 var usedProperties = Object[tableProperty] ||
40 (Object[tableProperty] = Object.create(null));
41
42 var rootProperty = "_${generateIsolateTagRoot()}";
43 for (var i = 0; ; i++) {
44 var property = intern(rootProperty + "_" + i + "_");
45 if (!(property in usedProperties)) {
46 usedProperties[property] = 1;
47 #isolateTag = property;
48 break;
49 }
50 }
51 }()
52 ''',
53 {'getIsolateTag': getIsolateTagAccess, 'isolateTag': isolateTagAccess});
54 }
55
56 jsAst.Expression generateDispatchPropertyNameInitialization() {
57 jsAst.Expression dispatchPropertyNameAccess =
58 generateEmbeddedGlobalAccess(embeddedNames.DISPATCH_PROPERTY_NAME);
59 jsAst.Expression getIsolateTagAccess =
60 generateEmbeddedGlobalAccess(embeddedNames.GET_ISOLATE_TAG);
61 return js('# = #("dispatch_record")',
62 [dispatchPropertyNameAccess,
63 getIsolateTagAccess]);
64 }
65
66 String generateIsolateTagRoot() {
67 // TODO(sra): MD5 of contributing source code or URIs?
68 return 'ZxYxX';
69 }
70 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/js_emitter/js_emitter.dart ('k') | pkg/compiler/lib/src/js_emitter/new_emitter/emitter.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698