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.
5 function attachListeners() {
6 var number1El = document.querySelector('#addend1');
7 var number2El = document.querySelector('#addend2');
8 var resultEl = document.querySelector('#result');
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]);
15 // The result is returned in handleMessage below.
18 document.getElementById('addSync').addEventListener('click', function() {
19 var value1 = parseInt(number1El.value);
20 var value2 = parseInt(number2El.value);
22 common.naclModule.postMessageAndAwaitResponse([value1, value2]);
24 // This is the result returned from the module synchronously (i.e. when the
25 // addSync button is pressed)
26 resultEl.textContent = result;
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;