Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(236)

Side by Side Diff: native_client_sdk/src/examples/api/messaging/example.js

Issue 781623002: [NaCl SDK] Messaging example (demonstrates postMessageAndAwaitResponse) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: nits Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 }
OLDNEW
« no previous file with comments | « native_client_sdk/src/examples/api/messaging/example.dsc ('k') | native_client_sdk/src/examples/api/messaging/index.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698