fix(compiler): keep `DOM.hasProperty` in sync between browser and transformer.

Right now, we always return true until
we have property schema support (#2014).

Fixes #2984
Closes #2981
This commit is contained in:
Tobias Bosch 2015-07-13 11:43:56 -07:00
parent 7ee6963f5d
commit b3a763a718
4 changed files with 71 additions and 63 deletions

View File

@ -98,17 +98,19 @@ final _keyCodeToKeyMap = const {
class BrowserDomAdapter extends GenericBrowserDomAdapter {
js.JsFunction _setProperty;
js.JsFunction _getProperty;
js.JsFunction _hasProperty;
BrowserDomAdapter() {
_setProperty = js.context.callMethod('eval', ['(function(el, prop, value) { el[prop] = value; })']);
_setProperty = js.context.callMethod('eval', ['(function(el, prop, value) { if (prop in el) el[prop] = value; })']);
_getProperty = js.context.callMethod('eval', ['(function(el, prop) { return el[prop]; })']);
_hasProperty = js.context.callMethod('eval', ['(function(el, prop) { return prop in el; })']);
}
static void makeCurrent() {
setRootDomAdapter(new BrowserDomAdapter());
}
bool hasProperty(Element element, String name) =>
_hasProperty.apply([element, name]);
bool hasProperty(Element element, String name) {
// Always return true as the serverside version html_adapter.dart does so.
// TODO: change this once we have schema support.
// Note: This nees to kept in sync with html_adapter.dart!
return true;
}
void setProperty(Element element, String name, Object value) =>
_setProperty.apply([element, name, value]);

View File

@ -11,7 +11,9 @@ class Html5LibDomAdapter implements DomAdapter {
}
hasProperty(element, String name) {
// This is needed for serverside compile to generate the right getters/setters...
// This is needed for serverside compile to generate the right getters/setters.
// TODO: change this once we have property schema support.
// Attention: Keep this in sync with browser_adapter.dart!
return true;
}

View File

@ -1245,6 +1245,7 @@ export function main() {
});
}));
if (!IS_DARTIUM) {
describe('Missing property bindings', () => {
it('should throw on bindings to unknown properties',
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
@ -1270,6 +1271,7 @@ export function main() {
.then((val) => { async.done(); });
}));
});
}
// Disabled until a solution is found, refs:
// - https://github.com/angular/angular/issues/776

View File

@ -22,6 +22,7 @@ export function main() {
var builder;
beforeEach(() => { builder = new ProtoViewBuilder(el('<div/>'), ViewType.EMBEDDED); });
if (!IS_DARTIUM) {
describe('verification of properties', () => {
it('should throw for unknown properties', () => {
@ -54,6 +55,7 @@ export function main() {
});
});
}
describe('property normalization', () => {
it('should normalize "innerHtml" to "innerHTML"', () => {