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

Issue 15026006: Support for extending native classes (Closed)

Created:
7 years, 7 months ago by sra1
Modified:
7 years, 4 months ago
Reviewers:
ahe, blois
CC:
reviews_dartlang.org
Visibility:
Public.

Description

First cut at extending native classes. Subclasses of native classes have to be treated largely like native classes since they require interceptors. The ugly part is collecting the set of subclasses of native classes without resolving all classes. Only plausible classes are resolved. Plausible classes have a superclass name that is native class (or subclass of native class). The name-keyed graph is collected and inverted to identify the true subclasses of native classes. Things that are missing from this CL: 1. I discussed with Peter a better way of finding which classes are subclasses of native classes by resolving the superclass. Peter's proposal will still require the graph inversion step but should be more precise. 2. It would be a good idea to replace the 'defineNativeSubclass' calls with more declarative static data on the class and post-process the classes. 3. We need to make sure that fields of subclasses of native classes do not conflict with any (potentially undeclared) properties of the base native class. 4. The compiler should do additional checking - The constructor must be a factory constructor. - No fields can have initializers. R=ahe@google.com Committed: https://code.google.com/p/dart/source/detail?r=26208

Patch Set 1 : rebase #

Patch Set 2 : #

Patch Set 3 : #

Patch Set 4 : #

Patch Set 5 : #

Patch Set 6 : #

Total comments: 6

Patch Set 7 : #

Total comments: 33

Patch Set 8 : #

Total comments: 6

Patch Set 9 : #

Patch Set 10 : #

Unified diffs Side-by-side diffs Delta from patch set Stats (+569 lines, -41 lines) Patch
M sdk/lib/_internal/compiler/implementation/elements/elements.dart View 1 2 3 4 5 6 7 8 2 chunks +7 lines, -1 line 0 comments Download
M sdk/lib/_internal/compiler/implementation/js_backend/backend.dart View 1 2 3 4 5 6 7 6 chunks +14 lines, -4 lines 0 comments Download
M sdk/lib/_internal/compiler/implementation/js_backend/emitter.dart View 1 2 3 4 5 6 7 8 7 chunks +56 lines, -8 lines 0 comments Download
M sdk/lib/_internal/compiler/implementation/js_backend/namer.dart View 1 2 3 4 5 6 7 8 1 chunk +2 lines, -2 lines 0 comments Download
M sdk/lib/_internal/compiler/implementation/js_backend/native_emitter.dart View 1 2 3 4 5 6 7 13 chunks +90 lines, -14 lines 0 comments Download
M sdk/lib/_internal/compiler/implementation/native_handler.dart View 1 2 3 4 5 6 7 4 chunks +127 lines, -0 lines 0 comments Download
M sdk/lib/_internal/compiler/implementation/ssa/builder.dart View 1 2 3 4 5 6 7 8 1 chunk +2 lines, -0 lines 0 comments Download
M sdk/lib/_internal/lib/foreign_helper.dart View 1 2 3 4 5 6 7 1 chunk +16 lines, -0 lines 0 comments Download
M sdk/lib/_internal/lib/interceptors.dart View 1 2 3 4 5 6 7 2 chunks +32 lines, -1 line 0 comments Download
M sdk/lib/_internal/lib/native_helper.dart View 1 2 3 4 5 6 7 8 4 chunks +67 lines, -9 lines 0 comments Download
M tests/compiler/dart2js/mock_compiler.dart View 1 2 3 4 5 6 7 8 9 1 chunk +1 line, -0 lines 0 comments Download
A tests/compiler/dart2js_native/subclassing_1_test.dart View 1 2 3 4 1 chunk +58 lines, -0 lines 0 comments Download
A tests/compiler/dart2js_native/subclassing_2_test.dart View 1 2 3 4 1 chunk +45 lines, -0 lines 0 comments Download
A tests/compiler/dart2js_native/subclassing_3_test.dart View 1 2 3 4 5 1 chunk +50 lines, -0 lines 0 comments Download
M tests/html/custom_elements_test.dart View 1 2 3 4 5 6 7 8 1 chunk +0 lines, -1 line 0 comments Download
M tests/utils/dummy_compiler_test.dart View 1 2 3 4 5 6 7 8 9 1 chunk +2 lines, -1 line 0 comments Download

Messages

Total messages: 10 (0 generated)
sra1
7 years, 4 months ago (2013-08-09 02:58:14 UTC) #1
ahe
I promised to take a closer look tomorrow, but I hope you have time to ...
7 years, 4 months ago (2013-08-12 20:47:35 UTC) #2
sra1
https://chromiumcodereview.appspot.com/15026006/diff/28001/sdk/lib/_internal/compiler/implementation/js_backend/backend.dart File sdk/lib/_internal/compiler/implementation/js_backend/backend.dart (right): https://chromiumcodereview.appspot.com/15026006/diff/28001/sdk/lib/_internal/compiler/implementation/js_backend/backend.dart#newcode203 sdk/lib/_internal/compiler/implementation/js_backend/backend.dart:203: Element mapTypeToInterceptor; On 2013/08/12 20:47:35, ahe wrote: > Please ...
7 years, 4 months ago (2013-08-12 23:06:14 UTC) #3
ahe
Comments so far, I need to read native_helper.dart and the tests. Nothing blocking, so expect ...
7 years, 4 months ago (2013-08-13 18:31:47 UTC) #4
sra1
https://chromiumcodereview.appspot.com/15026006/diff/35001/sdk/lib/_internal/compiler/implementation/js_backend/backend.dart File sdk/lib/_internal/compiler/implementation/js_backend/backend.dart (right): https://chromiumcodereview.appspot.com/15026006/diff/35001/sdk/lib/_internal/compiler/implementation/js_backend/backend.dart#newcode203 sdk/lib/_internal/compiler/implementation/js_backend/backend.dart:203: /** On 2013/08/13 18:31:47, ahe wrote: > Add newline ...
7 years, 4 months ago (2013-08-14 04:36:47 UTC) #5
ahe
Sorry, I lost track of time yesterday tracking down why I had broken the build. ...
7 years, 4 months ago (2013-08-14 10:52:47 UTC) #6
ahe
lgtm https://chromiumcodereview.appspot.com/15026006/diff/45001/sdk/lib/_internal/lib/native_helper.dart File sdk/lib/_internal/lib/native_helper.dart (right): https://chromiumcodereview.appspot.com/15026006/diff/45001/sdk/lib/_internal/lib/native_helper.dart#newcode268 sdk/lib/_internal/lib/native_helper.dart:268: * Associates tags with an interceptor. Called from ...
7 years, 4 months ago (2013-08-14 21:11:21 UTC) #7
sra1
Committed patchset #10 manually as r26208 (presubmit successful).
7 years, 4 months ago (2013-08-15 19:09:39 UTC) #8
sra1
https://chromiumcodereview.appspot.com/15026006/diff/45001/sdk/lib/_internal/lib/native_helper.dart File sdk/lib/_internal/lib/native_helper.dart (right): https://chromiumcodereview.appspot.com/15026006/diff/45001/sdk/lib/_internal/lib/native_helper.dart#newcode268 sdk/lib/_internal/lib/native_helper.dart:268: * Associates tags with an interceptor. Called from generated ...
7 years, 4 months ago (2013-08-15 19:13:00 UTC) #9
ahe
7 years, 4 months ago (2013-08-15 19:24:01 UTC) #10
Message was sent while issue was closed.
https://chromiumcodereview.appspot.com/15026006/diff/45001/sdk/lib/_internal/...
File sdk/lib/_internal/lib/native_helper.dart (right):

https://chromiumcodereview.appspot.com/15026006/diff/45001/sdk/lib/_internal/...
sdk/lib/_internal/lib/native_helper.dart:289: void
defineNativeMethodsCommon(String tags, var interceptorClass, bool isLeaf) {
On 2013/08/15 19:13:00, sra1 wrote:
> On 2013/08/14 21:11:22, ahe wrote:
> > I don't understand why this method exists. It seems like all of this can be
> > computed by the emitter and emitted like this:
> > 
> > $.interceptorToTag = [
> >   class1,
> >   tag,
> >   class2,
> >   tag,
> >   class3,
> >   tag1,
> >   class4,
> >   tag2
> > ];
> > 
> > $.interceptorsByTag = {
> >   tag1: $.InterceptorClass1,
> >   tag2: $.InterceptorClass2,
> > };
> > 
> > $.leafTags = {
> >   tag1: true,
> >   tag2: false,  
> > };
> 
> I generally agree, but done naively like this would add >15k to swarm and even
> more to trivial 'hello world' programs.
> The code splits strings containing multiple tags and the interceptorClass is
not
> the run time interceptor (i.e. the .prototype).
> 
> With just a map we would replace
> 
> // 100 calls to foo
> $.foo("tag1|tag2|...|tag50", $.InterceptorClass1)
> ...
> 
> with
> 
> // 300 properties here
> $.interceptorsByTag = {
>   tag1: $.InterceptorClass1.prototype,
>   tag2: $.InterceptorClass1.prototype,
>   ...
>   tag50: $.InterceptorClass1.prototype,
>   ...
> };
> 
> 
> Simply repeating the tags in $.leafTags adds 5k-10k and since they are
> interspersed with different data, the compression is merely OK, not great.
> 
> The current encoding has the property that very small programs list the HTML
and
> SVG dispatch tags once, mostly all together in one string.  We could probably
> emit a blob of data that can be processed, but it would effectively be the
loop
> that is 'unrolled' to the 'defineNativeMethods' family of calls.
> 
> One thing I have considered is 'registering' regular expressions to compress
the
> list of HTMLxxxElement names further.  That could not be a map key and would
> require a specific test ordering.
> 
> One option I have not explored yet is to attach the information to the class
or
> class-static definition and extract it in finishClasses.
> 

Thank you for the explanation. When I formulated this question, I overlooked the
split on line 294. Had I looked at swarm, this would have been obvious. But I'm
beginning to understand this much better which will be handy later :-)

Powered by Google App Engine
This is Rietveld 408576698