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"
25 #include "js/Printf.h"
26 #include "wasm/WasmTypeDecls.h"
29 using namespace js::wasm
;
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
);
37 bool wasm::TextToBinary(const char16_t
* text
, size_t textLen
, Bytes
* bytes
,
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
);
49 if (outBytesLength
== 0) {
50 *error
= JS_smprintf("missing bytes");
55 MOZ_ASSERT(outBytesLength
> 0);
56 bytes
->replaceRawBuffer(outBytes
, outBytesLength
);
61 MOZ_ASSERT(outErrorLength
> 0);
62 *error
= UniqueChars
{(char*)outError
};