Skip to content

Commit

Permalink
Revert "fixes #173, ability to use native JS indexers"
Browse files Browse the repository at this point in the history
This reverts commit 8dc1eeeb4dcc4d186f59513abd18f98e67c36339.

Review URL: https://codereview.chromium.org/1160343003
  • Loading branch information
John Messerly committed Jun 1, 2015
1 parent 59852b5 commit 9277398
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 96 deletions.
29 changes: 6 additions & 23 deletions pkg/dev_compiler/lib/src/codegen/js_codegen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ class JSCodegenVisitor extends GeneralizingAstVisitor with ConversionVisitor {
if (unit.directives.isNotEmpty) {
var libraryDir = unit.directives.first;
if (libraryDir is LibraryDirective) {
var jsName = findNodeAnnotation(libraryDir, _isJsNameAnnotation);
var jsName = getAnnotationValue(libraryDir, _isJsNameAnnotation);
jsDefaultValue = getConstantField(jsName, 'name', types.stringType);
}
}
Expand Down Expand Up @@ -329,7 +329,7 @@ class JSCodegenVisitor extends GeneralizingAstVisitor with ConversionVisitor {
// If we've already emitted this class, skip it.
var classElem = node.element;
var type = classElem.type;
var jsName = findNodeAnnotation(node, _isJsNameAnnotation);
var jsName = getAnnotationValue(node, _isJsNameAnnotation);

if (jsName != null) return _emitJsType(node.name.name, jsName);

Expand All @@ -350,7 +350,7 @@ class JSCodegenVisitor extends GeneralizingAstVisitor with ConversionVisitor {
_classHeritage(classElem), _emitClassMethods(node, ctors, fields));

String jsPeerName;
var jsPeer = findNodeAnnotation(node, _isJsPeerInterface);
var jsPeer = getAnnotationValue(node, _isJsPeerInterface);
if (jsPeer != null) {
jsPeerName = getConstantField(jsPeer, 'name', types.stringType);
}
Expand Down Expand Up @@ -475,7 +475,7 @@ class JSCodegenVisitor extends GeneralizingAstVisitor with ConversionVisitor {
jsMethods.add(_emitImplicitConstructor(node, fields));
}

bool hasJsPeer = findNodeAnnotation(node, _isJsPeerInterface) != null;
bool hasJsPeer = getAnnotationValue(node, _isJsPeerInterface) != null;

bool hasIterator = false;
for (var m in node.members) {
Expand Down Expand Up @@ -1349,12 +1349,7 @@ class JSCodegenVisitor extends GeneralizingAstVisitor with ConversionVisitor {

JS.Expression _emitSet(Expression lhs, Expression rhs) {
if (lhs is IndexExpression) {
var target = _getTarget(lhs);
if (_useNativeJsIndexer(target.staticType)) {
return js.call(
'#[#] = #', [_visit(target), _visit(lhs.index), _visit(rhs)]);
}
return _emitSend(target, '[]=', [lhs.index, rhs]);
return _emitSend(_getTarget(lhs), '[]=', [lhs.index, rhs]);
}

Expression target = null;
Expand Down Expand Up @@ -2121,18 +2116,9 @@ class JSCodegenVisitor extends GeneralizingAstVisitor with ConversionVisitor {

@override
visitIndexExpression(IndexExpression node) {
var target = _getTarget(node);
if (_useNativeJsIndexer(target.staticType)) {
return new JS.PropertyAccess(_visit(target), _visit(node.index));
}
return _emitSend(target, '[]', [node.index]);
return _emitSend(_getTarget(node), '[]', [node.index]);
}

// TODO(jmesserly): ideally we'd check the method and see if it is marked
// `external`, but that doesn't work because it isn't in the element model.
bool _useNativeJsIndexer(DartType type) =>
findElementAnnotation(type.element, _isJsIndexerAnnotation) != null;

/// Gets the target of a [PropertyAccess] or [IndexExpression].
/// Those two nodes are special because they're both allowed on left side of
/// an assignment expression and cascades.
Expand Down Expand Up @@ -2650,9 +2636,6 @@ String jsOutputPath(LibraryInfo info, Uri root) {
// TODO(jmesserly): validate the library. See issue #135.
bool _isJsNameAnnotation(DartObjectImpl value) => value.type.name == 'JsName';

bool _isJsIndexerAnnotation(DartObjectImpl value) =>
value.type.name == 'JsIndexer';

bool _isJsPeerInterface(DartObjectImpl value) =>
value.type.name == 'JsPeerInterface';

Expand Down
15 changes: 1 addition & 14 deletions pkg/dev_compiler/lib/src/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ String resourceOutputPath(Uri resourceUri, Uri entryUri) {
///
/// (v) => v.type.name == 'Deprecated' && v.type.element.library.isDartCore
///
DartObjectImpl findNodeAnnotation(
DartObjectImpl getAnnotationValue(
AnnotatedNode node, bool test(DartObjectImpl value)) {
for (var metadata in node.metadata) {
ElementAnnotationImpl element = metadata.elementAnnotation;
Expand All @@ -364,19 +364,6 @@ DartObjectImpl findNodeAnnotation(
return null;
}

/// Similar to [findNodeAnnotation] but starts from any element.
DartObjectImpl findElementAnnotation(
Element element, bool test(DartObjectImpl value)) {
for (var metadata in element.metadata) {
var evalResult = metadata.evaluationResult;
if (evalResult == null) continue;

var value = evalResult.value;
if (value != null && test(value)) return value;
}
return null;
}

/// Given a constant [value], a [fieldName], and an [expectedType], returns the
/// value of that field.
///
Expand Down
16 changes: 0 additions & 16 deletions pkg/dev_compiler/test/codegen/domtest.dart

This file was deleted.

16 changes: 0 additions & 16 deletions pkg/dev_compiler/test/codegen/expect/domtest.js

This file was deleted.

1 change: 0 additions & 1 deletion pkg/dev_compiler/test/codegen/expect/domtest.txt

This file was deleted.

7 changes: 2 additions & 5 deletions pkg/dev_compiler/test/codegen/expect/sunflower/dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,8 @@ var core = dart.import(core);
constructors: () => ({Overload: [Overload, []]})
});
let overload = dart.const(new Overload());
class JsIndexer extends core.Object {
JsIndexer() {
}
}
let EventListener = dart.typedef('EventListener', () => dart.functionType(dart.void, [Event]));
class Event extends core.Object {}
let InputElement = HTMLInputElement;
let CanvasElement = HTMLCanvasElement;
class RenderingContext extends core.Object {}
Expand All @@ -44,8 +41,8 @@ var core = dart.import(core);
exports.JsName = JsName;
exports.Overload = Overload;
exports.overload = overload;
exports.JsIndexer = JsIndexer;
exports.EventListener = EventListener;
exports.Event = Event;
exports.InputElement = InputElement;
exports.CanvasElement = CanvasElement;
exports.RenderingContext = RenderingContext;
Expand Down
21 changes: 0 additions & 21 deletions pkg/dev_compiler/test/codegen/sunflower/dom.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@ class Overload {
}
const overload = const Overload();

class JsIndexer {
const JsIndexer();
}

external Document get document;

@JsName(name: 'Document')
Expand All @@ -34,27 +30,10 @@ abstract class Document {
abstract class Element {
void addEventListener(String type, EventListener callback, [bool capture]);
String textContent;
NodeList get childNodes;
}

@JsName()
class Node {}

@JsName()
@JsIndexer()
class NodeList {
external NodeList();
external num get length;
external set length(num _);
external Node item(num index);

external Node operator [](num index);
external void operator []=(num index, Node);
}

typedef void EventListener(Event e);

@JsName()
abstract class Event {}

@JsName(name: 'HTMLInputElement')
Expand Down

0 comments on commit 9277398

Please sign in to comment.