no bug - Bumping Firefox l10n changesets r=release a=l10n-bump DONTBUILD CLOSED TREE
[gecko.git] / js / src / shell / WasmTesting.cpp
blob3d5aa3d9432954710bce81cac1a4f03834e59801
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 * vim: set ts=8 sts=2 et sw=2 tw=80:
4 * Copyright 2015 Mozilla Foundation
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
19 #include "shell/WasmTesting.h"
21 #include <inttypes.h>
22 #include <stdbool.h>
23 #include <stddef.h>
25 #include "js/Printf.h"
26 #include "wasm/WasmTypeDecls.h"
28 using namespace js;
29 using namespace js::wasm;
31 extern "C" {
32 bool wasm_text_to_binary(const char16_t* text, size_t text_len,
33 uint8_t** out_bytes, size_t* out_bytes_len,
34 uint8_t** out_error, size_t* out_error_len);
35 } // extern "C"
37 bool wasm::TextToBinary(const char16_t* text, size_t textLen, Bytes* bytes,
38 UniqueChars* error) {
39 uint8_t* outBytes = nullptr;
40 size_t outBytesLength = 0;
42 uint8_t* outError = nullptr;
43 size_t outErrorLength = 0;
45 bool result = wasm_text_to_binary(text, textLen, &outBytes, &outBytesLength,
46 &outError, &outErrorLength);
48 if (result) {
49 if (outBytesLength == 0) {
50 *error = JS_smprintf("missing bytes");
51 return false;
54 MOZ_ASSERT(outBytes);
55 MOZ_ASSERT(outBytesLength > 0);
56 bytes->replaceRawBuffer(outBytes, outBytesLength);
57 return true;
60 MOZ_ASSERT(outError);
61 MOZ_ASSERT(outErrorLength > 0);
62 *error = UniqueChars{(char*)outError};
63 return false;