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

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: 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 (c) 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 $(id) {
6 return document.querySelector(id);
7 }
dmichael (off chromium) 2014/12/03 23:33:33 I wouldn't define $ in an example... you can just
binji 2014/12/03 23:56:50 Done.
8
9 function attachListeners() {
10 var number1El = $('#addend1');
11 var number2El = $('#addend2');
12 var resultEl = $('#result');
13
14 document.getElementById('addAsync').addEventListener('click', function() {
15 var value1 = parseInt(number1El.value);
16 var value2 = parseInt(number2El.value);
17 common.naclModule.postMessage([value1, value2]);
18
19 // The result is returned in handleMessage below.
20 });
21
22 document.getElementById('addSync').addEventListener('click', function() {
23 var value1 = parseInt(number1El.value);
24 var value2 = parseInt(number2El.value);
25 var result =
26 common.naclModule.postMessageAndAwaitResponse([value1, value2]);
27
28 // This is the result returned from the module synchronously (i.e. when the
29 // addSync button is pressed)
30 resultEl.textContent = result;
31 });
32 }
33
34 // Called by the common.js module.
35 function handleMessage(message_event) {
36 // This is the result returned from the module asynchronously (i.e. when the
37 // addAsync button is pressed)
38 result.textContent = message_event.data;
39 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698