Changeset View
Changeset View
Standalone View
Standalone View
source/scriptinterface/ScriptConversions.cpp
/* Copyright (C) 2021 Wildfire Games. | /* Copyright (C) 2022 Wildfire Games. | ||||
* This file is part of 0 A.D. | * This file is part of 0 A.D. | ||||
* | * | ||||
* 0 A.D. is free software: you can redistribute it and/or modify | * 0 A.D. is free software: you can redistribute it and/or modify | ||||
* it under the terms of the GNU General Public License as published by | * it under the terms of the GNU General Public License as published by | ||||
* the Free Software Foundation, either version 2 of the License, or | * the Free Software Foundation, either version 2 of the License, or | ||||
* (at your option) any later version. | * (at your option) any later version. | ||||
* | * | ||||
* 0 A.D. is distributed in the hope that it will be useful, | * 0 A.D. is distributed in the hope that it will be useful, | ||||
▲ Show 20 Lines • Show All 90 Lines • ▼ Show 20 Lines | |||||
template<> bool Script::FromJSVal<std::wstring>(const ScriptRequest& rq, JS::HandleValue v, std::wstring& out) | template<> bool Script::FromJSVal<std::wstring>(const ScriptRequest& rq, JS::HandleValue v, std::wstring& out) | ||||
{ | { | ||||
FAIL_IF_NOT(v.isString() || v.isNumber() || v.isBoolean(), v); // allow implicit boolean/number conversions | FAIL_IF_NOT(v.isString() || v.isNumber() || v.isBoolean(), v); // allow implicit boolean/number conversions | ||||
JS::RootedString str(rq.cx, JS::ToString(rq.cx, v)); | JS::RootedString str(rq.cx, JS::ToString(rq.cx, v)); | ||||
if (!str) | if (!str) | ||||
FAIL("Argument must be convertible to a string"); | FAIL("Argument must be convertible to a string"); | ||||
if (JS_StringHasLatin1Chars(str)) | if (JS::StringHasLatin1Chars(str)) | ||||
{ | { | ||||
size_t length; | size_t length; | ||||
JS::AutoCheckCannotGC nogc; | JS::AutoCheckCannotGC nogc; | ||||
const JS::Latin1Char* ch = JS_GetLatin1StringCharsAndLength(rq.cx, nogc, str, &length); | const JS::Latin1Char* ch = JS_GetLatin1StringCharsAndLength(rq.cx, nogc, str, &length); | ||||
if (!ch) | if (!ch) | ||||
FAIL("JS_GetLatin1StringCharsAndLength failed"); | FAIL("JS_GetLatin1StringCharsAndLength failed"); | ||||
out.assign(ch, ch + length); | out.assign(ch, ch + length); | ||||
▲ Show 20 Lines • Show All 214 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator