OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 function attachListeners() { |
| 6 var number1El = document.querySelector('#addend1'); |
| 7 var number2El = document.querySelector('#addend2'); |
| 8 var resultEl = document.querySelector('#result'); |
| 9 |
| 10 document.getElementById('addAsync').addEventListener('click', function() { |
| 11 var value1 = parseInt(number1El.value); |
| 12 var value2 = parseInt(number2El.value); |
| 13 common.naclModule.postMessage([value1, value2]); |
| 14 |
| 15 // The result is returned in handleMessage below. |
| 16 }); |
| 17 |
| 18 document.getElementById('addSync').addEventListener('click', function() { |
| 19 var value1 = parseInt(number1El.value); |
| 20 var value2 = parseInt(number2El.value); |
| 21 var result = |
| 22 common.naclModule.postMessageAndAwaitResponse([value1, value2]); |
| 23 |
| 24 // This is the result returned from the module synchronously (i.e. when the |
| 25 // addSync button is pressed) |
| 26 resultEl.textContent = result; |
| 27 }); |
| 28 } |
| 29 |
| 30 // Called by the common.js module. |
| 31 function handleMessage(message_event) { |
| 32 // This is the result returned from the module asynchronously (i.e. when the |
| 33 // addAsync button is pressed) |
| 34 result.textContent = message_event.data; |
| 35 } |
OLD | NEW |