aboutsummaryrefslogtreecommitdiff
path: root/files/fr/web/javascript/reference/objets_globaux/webassembly/validate/index.html
blob: c00eb54e12a3acccc9d91de97b3ba9d987d11a4e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
---
title: WebAssembly.validate()
slug: Web/JavaScript/Reference/Objets_globaux/WebAssembly/validate
tags:
  - API
  - JavaScript
  - Méthode
  - Reference
  - WebAssembly
translation_of: Web/JavaScript/Reference/Global_Objects/WebAssembly/validate
---
<div>{{JSRef}}</div>

<p>La fonction <strong><code>WebAssembly.validate()</code></strong> permet de valider un <a href="/fr/docs/Web/JavaScript/Tableaux_typés">tableau typé</a> de <em>bytecode</em> WebAssembly et renvoie un booléen qui indique si le contenu du tableau forme un module WebAssembly valide (<code>true</code>) ou non (<code>false</code>).</p>

<h2 id="Syntaxe">Syntaxe</h2>

<pre class="syntaxbox">WebAssembly.validate(bufferSource);</pre>

<h3 id="Paramètres">Paramètres</h3>

<dl>
 <dt><code>bufferSource</code></dt>
 <dd>Un <a href="/fr/docs/Web/JavaScript/Reference/Objets_globaux/TypedArray">tableau typé</a> ou un {{jsxref("ArrayBuffer")}} qui contient le <em>bytecode</em> du module qu'on souhaite valider.</dd>
</dl>

<h3 id="Valeur_de_retour">Valeur de retour</h3>

<p>Un booléen qui indique si la source est un code WebAssembly valide (<code>true</code>) ou non (<code>false</code>).</p>

<h3 id="Exceptions">Exceptions</h3>

<p>Si la valeur passée en argument n'est pas un tableau typé ou un {{jsxref("ArrayBuffer")}}, une exception {{jsxref("TypeError")}} sera levée.</p>

<h2 id="Exemples">Exemples</h2>

<p>Dans l'exemple suivant, (cf. le fichier <code>validate.html</code> du <a href="https://github.com/mdn/webassembly-examples/blob/master/js-api-examples/validate.html">code source</a>, ainsi que <a href="https://mdn.github.io/webassembly-examples/js-api-examples/validate.html">l'exemple <em>live</em></a>), on récupère un module .wasm et on le convertit en un tableau typé. Ensuite, on appelle la méthode <code>validate()</code> afin de vérifier si le module est valide.</p>

<pre class="brush: js">fetch('simple.wasm').then(response =&gt;
  response.arrayBuffer()
).then(function(bytes) {
  var valid = WebAssembly.validate(bytes);
  console.log("Les octets forment un module "
    + (valid ? "" : "in") + "valide.");
});
</pre>

<h2 id="Spécifications">Spécifications</h2>

<table class="standard-table">
 <thead>
  <tr>
   <th scope="col">Spécification</th>
   <th scope="col">État</th>
   <th scope="col">Commentaires</th>
  </tr>
 </thead>
 <tbody>
  <tr>
   <td>{{SpecName('WebAssembly JS', '#webassemblyvalidate', 'validate()')}}</td>
   <td>{{Spec2('WebAssembly JS')}}</td>
   <td>Brouillon de définition initiale pour WebAssembly.</td>
  </tr>
 </tbody>
</table>

<h2 id="Compatibilité_des_navigateurs">Compatibilité des navigateurs</h2>

<div>
<div class="hidden">Ce tableau de compatibilité a été généré à partir de données structurées. Si vous souhaitez contribuer à ces données, n'hésitez pas à envoyer une <em>pull request</em> sur <a href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a>.</div>

<p>{{Compat("javascript.builtins.WebAssembly.validate")}}</p>
</div>

<h2 id="Voir_aussi">Voir aussi</h2>

<ul>
 <li><a href="/fr/docs/WebAssembly">Le portail WebAssembly</a></li>
 <li><a href="/fr/docs/WebAssembly/Concepts">Les concepts relatifs à WebAssembly</a></li>
 <li><a href="/fr/docs/WebAssembly/Using_the_JavaScript_API">Utiliser l'API JavaScript WebAssembly</a></li>
</ul>