From a48732850420859b218c04b280a2f6c412525f0b Mon Sep 17 00:00:00 2001 From: Kalev Lember Date: Tue, 15 May 2018 21:14:16 +0200 Subject: [PATCH] Revert "js: Convert scripts to UTF-16 before evaluating" RHEL 7 libstdc++ 4.8 doesn't have header that gjs needs. In order to work this around, this commit reverts the patch that introduced the requirement. This reverts commit bc36f39ff09629e1b4c5c54f334028d2b2f8c545. --- gjs/jsapi-util.cpp | 14 ++++++-------- gjs/module.cpp | 15 ++++++--------- 2 files changed, 12 insertions(+), 17 deletions(-) diff --git a/gjs/jsapi-util.cpp b/gjs/jsapi-util.cpp index ed3e6492..8b686048 100644 --- a/gjs/jsapi-util.cpp +++ b/gjs/jsapi-util.cpp @@ -1,58 +1,56 @@ /* -*- mode: C++; c-basic-offset: 4; indent-tabs-mode: nil; -*- */ /* * Copyright (c) 2008 litl, LLC * Copyright (c) 2009 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to * deal in the Software without restriction, including without limitation the * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or * sell copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS * IN THE SOFTWARE. */ #include -#include -#include #include "jsapi-wrapper.h" #include #include #include #include #include #include "jsapi-class.h" #include "jsapi-util.h" #include "context-private.h" #include #include #include GQuark gjs_util_error_quark (void) { return g_quark_from_static_string ("gjs-util-error-quark"); } bool gjs_object_get_property(JSContext *cx, JS::HandleObject obj, GjsConstString property_name, JS::MutableHandleValue value_p) { return JS_GetPropertyById(cx, obj, gjs_context_get_const_string(cx, property_name), @@ -826,58 +824,58 @@ gjs_strip_unix_shebang(const char *script, bool gjs_eval_with_scope(JSContext *context, JS::HandleObject object, const char *script, ssize_t script_len, const char *filename, JS::MutableHandleValue retval) { int start_line_number = 1; JSAutoRequest ar(context); size_t real_len = script_len; if (script_len < 0) real_len = strlen(script); script = gjs_strip_unix_shebang(script, &real_len, &start_line_number); /* log and clear exception if it's set (should not be, normally...) */ if (JS_IsExceptionPending(context)) { g_warning("gjs_eval_in_scope called with a pending exception"); return false; } JS::RootedObject eval_obj(context, object); if (!eval_obj) eval_obj = JS_NewPlainObject(context); JS::CompileOptions options(context); - options.setFileAndLine(filename, start_line_number) + options.setUTF8(true) + .setFileAndLine(filename, start_line_number) .setSourceIsLazy(true); - std::wstring_convert, char16_t> convert; - std::u16string utf16_string = convert.from_bytes(script); - JS::SourceBufferHolder buf(utf16_string.c_str(), utf16_string.size(), - JS::SourceBufferHolder::NoOwnership); + JS::RootedScript compiled_script(context); + if (!JS::Compile(context, options, script, real_len, &compiled_script)) + return false; JS::AutoObjectVector scope_chain(context); if (!scope_chain.append(eval_obj)) g_error("Unable to append to vector"); - if (!JS::Evaluate(context, scope_chain, options, buf, retval)) + if (!JS_ExecuteScript(context, scope_chain, compiled_script, retval)) return false; gjs_schedule_gc_if_needed(context); if (JS_IsExceptionPending(context)) { g_warning("EvaluateScript returned true but exception was pending; " "did somebody call gjs_throw() without returning false?"); return false; } gjs_debug(GJS_DEBUG_CONTEXT, "Script evaluation succeeded"); return true; } diff --git a/gjs/module.cpp b/gjs/module.cpp index cc6657a7..4b8bd40c 100644 --- a/gjs/module.cpp +++ b/gjs/module.cpp @@ -1,56 +1,53 @@ /* -*- mode: C++; c-basic-offset: 4; indent-tabs-mode: nil; -*- */ /* * Copyright (c) 2017 Philip Chimento * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to * deal in the Software without restriction, including without limitation the * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or * sell copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS * IN THE SOFTWARE. */ -#include -#include - #include #include "jsapi-util.h" #include "jsapi-wrapper.h" #include "module.h" #include "util/log.h" class GjsModule { char *m_name; GjsModule(const char *name) { m_name = g_strdup(name); } ~GjsModule() { g_free(m_name); } /* Private data accessors */ static inline GjsModule * priv(JSObject *module) { return static_cast(JS_GetPrivate(module)); } /* Creates a JS module object. Use instead of the class's constructor */ static JSObject * @@ -62,74 +59,74 @@ class GjsModule { return module; } /* Defines the empty module as a property on the importer */ bool define_import(JSContext *cx, JS::HandleObject module, JS::HandleObject importer, JS::HandleId name) { if (!JS_DefinePropertyById(cx, importer, name, module, GJS_MODULE_PROP_FLAGS & ~JSPROP_PERMANENT)) { gjs_debug(GJS_DEBUG_IMPORTER, "Failed to define '%s' in importer", m_name); return false; } return true; } /* Carries out the actual execution of the module code */ bool evaluate_import(JSContext *cx, JS::HandleObject module, const char *script, size_t script_len, const char *filename, int line_number) { JS::CompileOptions options(cx); - options.setFileAndLine(filename, line_number) + options.setUTF8(true) + .setFileAndLine(filename, line_number) .setSourceIsLazy(true); - std::wstring_convert, char16_t> convert; - std::u16string utf16_string = convert.from_bytes(script); - JS::SourceBufferHolder buf(utf16_string.c_str(), utf16_string.size(), - JS::SourceBufferHolder::NoOwnership); + JS::RootedScript compiled_script(cx); + if (!JS::Compile(cx, options, script, script_len, &compiled_script)) + return false; JS::AutoObjectVector scope_chain(cx); if (!scope_chain.append(module)) g_error("Unable to append to vector"); JS::RootedValue ignored_retval(cx); - if (!JS::Evaluate(cx, scope_chain, options, buf, &ignored_retval)) + if (!JS_ExecuteScript(cx, scope_chain, compiled_script, &ignored_retval)) return false; gjs_schedule_gc_if_needed(cx); gjs_debug(GJS_DEBUG_IMPORTER, "Importing module %s succeeded", m_name); return true; } /* Loads JS code from a file and imports it */ bool import_file(JSContext *cx, JS::HandleObject module, GFile *file) { GError *error = nullptr; char *unowned_script; size_t script_len = 0; int start_line_number = 1; if (!(g_file_load_contents(file, nullptr, &unowned_script, &script_len, nullptr, &error))) { gjs_throw_g_error(cx, error); return false; } GjsAutoChar script = unowned_script; /* steals ownership */ g_assert(script != nullptr); const char *stripped_script = -- 2.17.1