|
394 | 394 | return this.bindings.value = value; |
395 | 395 | } |
396 | 396 |
|
397 | | - function updateSelect(select, property, value, retries) { |
398 | | - select[property] = value; |
399 | | - if (!retries || select[property] == value) |
400 | | - return |
401 | | - |
402 | | - // The binding may wish to bind to an <option> which has not yet been |
403 | | - // produced by a child <template>. Delay |retries| times. |
404 | | - ensureScheduled(function() { |
405 | | - updateSelect(select, property, value, retries - 1); |
406 | | - }); |
407 | | - } |
408 | | - |
409 | | - function selectBinding(select, property) { |
410 | | - return function(value) { |
411 | | - updateSelect(select, property, value); |
412 | | - } |
413 | | - } |
414 | | - |
415 | 397 | HTMLSelectElement.prototype.bind = function(name, value, oneTime) { |
416 | 398 | if (name === 'selectedindex') |
417 | 399 | name = 'selectedIndex'; |
|
422 | 404 | this.removeAttribute(name); |
423 | 405 |
|
424 | 406 | if (oneTime) |
425 | | - return updateSelect(this, name, value); |
| 407 | + return updateInput(this, name, value); |
426 | 408 |
|
427 | 409 | unbind(this, name); |
428 | 410 | bindInputEvent(this, name, value); |
429 | | - updateSelect(this, name, value.open(selectBinding(this, name)), 2); |
| 411 | + updateInput(this, name, |
| 412 | + value.open(inputBinding(this, name))); |
430 | 413 | return this.bindings[name] = value; |
431 | 414 | } |
432 | | - |
433 | | - // TODO(rafaelw): We should polyfill a Microtask Promise and define it if it isn't. |
434 | | - var ensureScheduled = function() { |
435 | | - // We need to ping-pong between two Runners in order for the tests to |
436 | | - // simulate proper end-of-microtask behavior for Object.observe. Without |
437 | | - // this, we'll continue delivering to a single observer without allowing |
438 | | - // other observers in the same microtask to make progress. |
439 | | - |
440 | | - function Runner(nextRunner) { |
441 | | - this.nextRunner = nextRunner; |
442 | | - this.value = false; |
443 | | - this.lastValue = this.value; |
444 | | - this.scheduled = []; |
445 | | - this.scheduledIds = []; |
446 | | - this.running = false; |
447 | | - this.observer = new PathObserver(this, 'value'); |
448 | | - this.observer.open(this.run, this); |
449 | | - } |
450 | | - |
451 | | - Runner.prototype = { |
452 | | - schedule: function(async, id) { |
453 | | - if (this.scheduledIds[id]) |
454 | | - return; |
455 | | - |
456 | | - if (this.running) |
457 | | - return this.nextRunner.schedule(async, id); |
458 | | - |
459 | | - this.scheduledIds[id] = true; |
460 | | - this.scheduled.push(async); |
461 | | - |
462 | | - if (this.lastValue !== this.value) |
463 | | - return; |
464 | | - |
465 | | - this.value = !this.value; |
466 | | - }, |
467 | | - |
468 | | - run: function() { |
469 | | - this.running = true; |
470 | | - |
471 | | - for (var i = 0; i < this.scheduled.length; i++) { |
472 | | - var async = this.scheduled[i]; |
473 | | - var id = async[idExpando]; |
474 | | - this.scheduledIds[id] = false; |
475 | | - |
476 | | - if (typeof async === 'function') |
477 | | - async(); |
478 | | - else |
479 | | - async.resolve(); |
480 | | - } |
481 | | - |
482 | | - this.scheduled = []; |
483 | | - this.scheduledIds = []; |
484 | | - this.lastValue = this.value; |
485 | | - |
486 | | - this.running = false; |
487 | | - } |
488 | | - } |
489 | | - |
490 | | - var runner = new Runner(new Runner()); |
491 | | - |
492 | | - var nextId = 1; |
493 | | - var idExpando = '__scheduledId__'; |
494 | | - |
495 | | - function ensureScheduled(async) { |
496 | | - var id = async[idExpando]; |
497 | | - if (!async[idExpando]) { |
498 | | - id = nextId++; |
499 | | - async[idExpando] = id; |
500 | | - } |
501 | | - |
502 | | - runner.schedule(async, id); |
503 | | - } |
504 | | - |
505 | | - return ensureScheduled; |
506 | | - }(); |
507 | | - |
508 | 415 | })(this); |
0 commit comments