2025-02-05 12:40:54 +10:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
Numerous changes with focus on feature and stability parity across Windows, Linux and MacOS platforms
Added new Makefile that handles compiling UOX3 and Spidermonkey on both Linux and MacOS (punt)
Added VS solution (SpiderMonkey.sln) and VC++ project files for compiling SpiderMonkey on Windows (Xuri)
Updated SpiderMonkey from v1.6.0 to v1.7.0
Added optimization flag -O2 for release build in CMakeLists.txt in project root (Xuri)
Added StringUtility file with general common string manipulation functions (punt)
Updated RandomNum function to use a "seedless" random number generator from C++11 instead of the old C rand() function. (punt)
Overall code cleanup to remove/replace platform-dependent code (punt)
Replaced potentially unsafe usage of C string stuff like sprintf, vsprintf, vsnprintf, strncat, strcpy and strlen throughout the code with calls to a format() function containing only a single, safe use of vsnprintf, ensuring there's a single place of failure if there's anything to fix and and making it easy to potentially replace this with std::format from C++20 when the time comes. (punt)
Replaced usage of char in many places with std::string (punt)
Started process of replacing UString usage with functions provided through StringUtility instead (punt)
Replaced platform specific fileIO handling in Windows/Linux with cross-platform C++17 standard std::filesystem (punt)
Replaced platform specific time handling by using cross-platform chrono library (punt)
Removed UOX namespace to reduce complexity (punt)
Elimitated template code approach to singletons for more modern c++ constructs, removing dependices in the process (punt)
Removed ODBC support; it hasn't been touched since the initial implementation in 2008, and there is a lack of someone to maintain the code. (punt)
Removed some platform specific files like uoxlinux.h, which is no longer required (punt)
Removed legacy crash protection code, and removed support for cluox (punt)
Removed legacy "support" for Borland compiler (punt)
Removed legacy VC++ 6 Workspace/Project files, VS2005 Solution/Project files, as these are no longer supported (Xuri)
Removed legacy BUILD folder with outdated compilation instructions (Xuri)
Removed old Changelog file (merged into Changelog.txt) (Xuri)
Fixed a pointer bug for items in multis on world load (punt)
Fixed a dictionary related issue that caused segmentation faults on Linux/MacOS (punt)
Fixed an issue with callbacks to JS scripts that caused segmentation faults on Linux/MacOS (punt)
Paths in uox.ini should now load properly on all platforms regardless of whether those paths use slashes or backslashes, and whether or not they end in a slash/backslash. (punt)
Moved to c++17 style of threading, and got rid of threadsafeobject.cpp/h (punt)
Replaced parsing of UOX.INI tags with a system that's more easily maintainable (punt)
Added some new commands to js/commands/custom/misc-cmd.js (Xuri)
cont // Targeted item will be made a container, set to nondecay and movable 2
endfight // Targeted character (and character being fought) will stop fighting
getmulti // Get multiObject for targeted item
finditem // Find item at layer X
movespeed // Set movement speed of target player (0x0 Normal, 0x1 Mounted, 0x2 Slow (walk only), 0x3 Hybrid ("jog"?), 0x4 Frozen)
Added new HTML based documentation in docs folder, and removed many old legacy docs that are either incorporated into this document already or no longer relevant for the current UOX3 version (Xuri)
Co-Authored-By: Charles Kerr <punt1959@users.noreply.github.com>
2020-09-07 18:09:55 +08:00
|
|
|
* vim: set ts=8 sw=4 et tw=78:
|
2018-09-08 18:08:48 +08:00
|
|
|
*
|
|
|
|
|
* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
|
*
|
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
|
*
|
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
|
* License.
|
|
|
|
|
*
|
|
|
|
|
* The Original Code is Mozilla Communicator client code, released
|
|
|
|
|
* March 31, 1998.
|
|
|
|
|
*
|
|
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
|
* Netscape Communications Corporation.
|
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
|
*
|
|
|
|
|
* Contributor(s):
|
|
|
|
|
*
|
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
|
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
|
|
|
|
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
|
*
|
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* JS script operations.
|
|
|
|
|
*/
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include "jstypes.h"
|
2025-02-05 12:40:54 +10:00
|
|
|
#include "jsstdint.h"
|
2025-03-19 21:25:58 +10:00
|
|
|
#include "jsutil.h"
|
2018-09-08 18:08:48 +08:00
|
|
|
#include "jsprf.h"
|
|
|
|
|
#include "jsapi.h"
|
|
|
|
|
#include "jsatom.h"
|
|
|
|
|
#include "jscntxt.h"
|
2025-02-03 12:35:24 +10:00
|
|
|
#include "jsversion.h"
|
2018-09-08 18:08:48 +08:00
|
|
|
#include "jsdbgapi.h"
|
|
|
|
|
#include "jsemit.h"
|
|
|
|
|
#include "jsfun.h"
|
|
|
|
|
#include "jsinterp.h"
|
|
|
|
|
#include "jslock.h"
|
|
|
|
|
#include "jsnum.h"
|
|
|
|
|
#include "jsopcode.h"
|
2023-07-12 13:27:26 +10:00
|
|
|
#include "jsparse.h"
|
2025-02-03 12:35:24 +10:00
|
|
|
#include "jsscope.h"
|
2018-09-08 18:08:48 +08:00
|
|
|
#include "jsscript.h"
|
2025-02-05 12:40:54 +10:00
|
|
|
#include "jstracer.h"
|
2018-09-08 18:08:48 +08:00
|
|
|
#if JS_HAS_XDR
|
|
|
|
|
#include "jsxdrapi.h"
|
|
|
|
|
#endif
|
2025-03-19 21:25:58 +10:00
|
|
|
#include "methodjit/MethodJIT.h"
|
2018-09-08 18:08:48 +08:00
|
|
|
|
2025-03-19 21:25:58 +10:00
|
|
|
#include "jsinterpinlines.h"
|
2025-02-05 12:40:54 +10:00
|
|
|
#include "jsobjinlines.h"
|
|
|
|
|
#include "jsscriptinlines.h"
|
2018-09-08 18:08:48 +08:00
|
|
|
|
2025-02-05 12:40:54 +10:00
|
|
|
using namespace js;
|
2025-03-19 21:25:58 +10:00
|
|
|
using namespace js::gc;
|
2018-09-08 18:08:48 +08:00
|
|
|
|
2025-03-19 21:25:58 +10:00
|
|
|
namespace js {
|
2018-09-08 18:08:48 +08:00
|
|
|
|
2025-03-19 21:25:58 +10:00
|
|
|
BindingKind
|
|
|
|
|
Bindings::lookup(JSContext *cx, JSAtom *name, uintN *indexp) const
|
|
|
|
|
{
|
|
|
|
|
JS_ASSERT(lastBinding);
|
|
|
|
|
|
|
|
|
|
Shape *shape =
|
|
|
|
|
SHAPE_FETCH(Shape::search(cx->runtime, const_cast<Shape **>(&lastBinding),
|
|
|
|
|
ATOM_TO_JSID(name)));
|
|
|
|
|
if (!shape)
|
|
|
|
|
return NONE;
|
|
|
|
|
|
|
|
|
|
if (indexp)
|
|
|
|
|
*indexp = shape->shortid;
|
|
|
|
|
|
|
|
|
|
if (shape->getter() == GetCallArg)
|
|
|
|
|
return ARGUMENT;
|
|
|
|
|
if (shape->getter() == GetCallUpvar)
|
|
|
|
|
return UPVAR;
|
|
|
|
|
|
|
|
|
|
return shape->writable() ? VARIABLE : CONSTANT;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
Bindings::add(JSContext *cx, JSAtom *name, BindingKind kind)
|
|
|
|
|
{
|
|
|
|
|
JS_ASSERT(lastBinding);
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* We still follow 10.2.3 of ES3 and make argument and variable properties
|
|
|
|
|
* of the Call objects enumerable. ES5 reformulated all of its Clause 10 to
|
|
|
|
|
* avoid objects as activations, something we should do too.
|
|
|
|
|
*/
|
|
|
|
|
uintN attrs = JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_SHARED;
|
|
|
|
|
|
|
|
|
|
uint16 *indexp;
|
|
|
|
|
PropertyOp getter;
|
|
|
|
|
StrictPropertyOp setter;
|
|
|
|
|
uint32 slot = JSObject::CALL_RESERVED_SLOTS;
|
|
|
|
|
|
|
|
|
|
if (kind == ARGUMENT) {
|
|
|
|
|
JS_ASSERT(nvars == 0);
|
|
|
|
|
JS_ASSERT(nupvars == 0);
|
|
|
|
|
indexp = &nargs;
|
|
|
|
|
getter = GetCallArg;
|
|
|
|
|
setter = SetCallArg;
|
|
|
|
|
slot += nargs;
|
|
|
|
|
} else if (kind == UPVAR) {
|
|
|
|
|
indexp = &nupvars;
|
|
|
|
|
getter = GetCallUpvar;
|
|
|
|
|
setter = SetCallUpvar;
|
|
|
|
|
slot = SHAPE_INVALID_SLOT;
|
|
|
|
|
} else {
|
|
|
|
|
JS_ASSERT(kind == VARIABLE || kind == CONSTANT);
|
|
|
|
|
JS_ASSERT(nupvars == 0);
|
|
|
|
|
|
|
|
|
|
indexp = &nvars;
|
|
|
|
|
getter = GetCallVar;
|
|
|
|
|
setter = SetCallVar;
|
|
|
|
|
if (kind == CONSTANT)
|
|
|
|
|
attrs |= JSPROP_READONLY;
|
|
|
|
|
slot += nargs + nvars;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (*indexp == BINDING_COUNT_LIMIT) {
|
|
|
|
|
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL,
|
|
|
|
|
(kind == ARGUMENT)
|
|
|
|
|
? JSMSG_TOO_MANY_FUN_ARGS
|
|
|
|
|
: JSMSG_TOO_MANY_LOCALS);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
jsid id;
|
|
|
|
|
if (!name) {
|
|
|
|
|
JS_ASSERT(kind == ARGUMENT); /* destructuring */
|
|
|
|
|
id = INT_TO_JSID(nargs);
|
|
|
|
|
} else {
|
|
|
|
|
id = ATOM_TO_JSID(name);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Shape child(id, getter, setter, slot, attrs, Shape::HAS_SHORTID, *indexp);
|
|
|
|
|
|
|
|
|
|
Shape *shape = lastBinding->getChild(cx, child, &lastBinding);
|
|
|
|
|
if (!shape)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
JS_ASSERT(lastBinding == shape);
|
|
|
|
|
++*indexp;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
jsuword *
|
|
|
|
|
Bindings::getLocalNameArray(JSContext *cx, JSArenaPool *pool)
|
|
|
|
|
{
|
|
|
|
|
JS_ASSERT(lastBinding);
|
|
|
|
|
|
|
|
|
|
JS_ASSERT(hasLocalNames());
|
|
|
|
|
|
|
|
|
|
uintN n = countLocalNames();
|
|
|
|
|
jsuword *names;
|
|
|
|
|
|
|
|
|
|
JS_ASSERT(SIZE_MAX / size_t(n) > sizeof *names);
|
|
|
|
|
JS_ARENA_ALLOCATE_CAST(names, jsuword *, pool, size_t(n) * sizeof *names);
|
|
|
|
|
if (!names) {
|
|
|
|
|
js_ReportOutOfScriptQuota(cx);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
|
for (uintN i = 0; i != n; i++)
|
|
|
|
|
names[i] = 0xdeadbeef;
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
for (Shape::Range r = lastBinding; !r.empty(); r.popFront()) {
|
|
|
|
|
const Shape &shape = r.front();
|
|
|
|
|
uintN index = uint16(shape.shortid);
|
|
|
|
|
jsuword constFlag = 0;
|
|
|
|
|
|
|
|
|
|
if (shape.getter() == GetCallArg) {
|
|
|
|
|
JS_ASSERT(index < nargs);
|
|
|
|
|
} else if (shape.getter() == GetCallUpvar) {
|
|
|
|
|
JS_ASSERT(index < nupvars);
|
|
|
|
|
index += nargs + nvars;
|
|
|
|
|
} else {
|
|
|
|
|
JS_ASSERT(index < nvars);
|
|
|
|
|
index += nargs;
|
|
|
|
|
if (!shape.writable())
|
|
|
|
|
constFlag = 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
JSAtom *atom;
|
|
|
|
|
if (JSID_IS_ATOM(shape.id)) {
|
|
|
|
|
atom = JSID_TO_ATOM(shape.id);
|
|
|
|
|
} else {
|
|
|
|
|
JS_ASSERT(JSID_IS_INT(shape.id));
|
|
|
|
|
JS_ASSERT(shape.getter() == GetCallArg);
|
|
|
|
|
atom = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
names[index] = jsuword(atom);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
|
for (uintN i = 0; i != n; i++)
|
|
|
|
|
JS_ASSERT(names[i] != 0xdeadbeef);
|
|
|
|
|
#endif
|
|
|
|
|
return names;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const Shape *
|
|
|
|
|
Bindings::lastArgument() const
|
|
|
|
|
{
|
|
|
|
|
JS_ASSERT(lastBinding);
|
|
|
|
|
|
|
|
|
|
const js::Shape *shape = lastVariable();
|
|
|
|
|
if (nvars > 0) {
|
|
|
|
|
while (shape->previous() && shape->getter() != GetCallArg)
|
|
|
|
|
shape = shape->previous();
|
|
|
|
|
}
|
|
|
|
|
return shape;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const Shape *
|
|
|
|
|
Bindings::lastVariable() const
|
|
|
|
|
{
|
|
|
|
|
JS_ASSERT(lastBinding);
|
|
|
|
|
|
|
|
|
|
const js::Shape *shape = lastUpvar();
|
|
|
|
|
if (nupvars > 0) {
|
|
|
|
|
while (shape->getter() == GetCallUpvar)
|
|
|
|
|
shape = shape->previous();
|
|
|
|
|
}
|
|
|
|
|
return shape;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const Shape *
|
|
|
|
|
Bindings::lastUpvar() const
|
|
|
|
|
{
|
|
|
|
|
JS_ASSERT(lastBinding);
|
|
|
|
|
return lastBinding;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
Bindings::sharpSlotBase(JSContext *cx)
|
|
|
|
|
{
|
|
|
|
|
JS_ASSERT(lastBinding);
|
|
|
|
|
#if JS_HAS_SHARP_VARS
|
|
|
|
|
if (JSAtom *name = js_Atomize(cx, "#array", 6, 0)) {
|
|
|
|
|
uintN index = uintN(-1);
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
|
BindingKind kind =
|
|
|
|
|
#endif
|
|
|
|
|
lookup(cx, name, &index);
|
|
|
|
|
JS_ASSERT(kind == VARIABLE);
|
|
|
|
|
return int(index);
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
Bindings::makeImmutable()
|
|
|
|
|
{
|
|
|
|
|
JS_ASSERT(lastBinding);
|
|
|
|
|
Shape *shape = lastBinding;
|
|
|
|
|
if (shape->inDictionary()) {
|
|
|
|
|
do {
|
|
|
|
|
JS_ASSERT(!shape->frozen());
|
|
|
|
|
shape->setFrozen();
|
|
|
|
|
} while ((shape = shape->parent) != NULL);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
Bindings::trace(JSTracer *trc)
|
|
|
|
|
{
|
|
|
|
|
for (const Shape *shape = lastBinding; shape; shape = shape->previous())
|
|
|
|
|
shape->trace(trc);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace js
|
2018-09-08 18:08:48 +08:00
|
|
|
|
2023-07-12 13:27:26 +10:00
|
|
|
#if JS_HAS_XDR
|
2018-09-08 18:08:48 +08:00
|
|
|
|
2025-03-19 21:25:58 +10:00
|
|
|
enum ScriptBits {
|
|
|
|
|
NoScriptRval,
|
|
|
|
|
SavedCallerFun,
|
|
|
|
|
HasSharps,
|
|
|
|
|
StrictModeCode,
|
|
|
|
|
UsesEval,
|
|
|
|
|
UsesArguments
|
|
|
|
|
};
|
|
|
|
|
|
2018-09-08 18:08:48 +08:00
|
|
|
JSBool
|
2025-03-19 21:25:58 +10:00
|
|
|
js_XDRScript(JSXDRState *xdr, JSScript **scriptp, JSBool *hasMagic)
|
2018-09-08 18:08:48 +08:00
|
|
|
{
|
2025-03-19 21:25:58 +10:00
|
|
|
JSScript *oldscript;
|
2023-07-12 13:27:26 +10:00
|
|
|
JSBool ok;
|
|
|
|
|
jsbytecode *code;
|
2025-03-19 21:25:58 +10:00
|
|
|
uint32 length, lineno, nslots;
|
|
|
|
|
uint32 natoms, nsrcnotes, ntrynotes, nobjects, nregexps, nconsts, i;
|
|
|
|
|
uint32 prologLength, version, encodedClosedCount;
|
|
|
|
|
uint16 nClosedArgs = 0, nClosedVars = 0;
|
2023-07-12 13:27:26 +10:00
|
|
|
JSPrincipals *principals;
|
|
|
|
|
uint32 encodeable;
|
2018-09-08 18:08:48 +08:00
|
|
|
JSBool filenameWasSaved;
|
2025-03-19 21:25:58 +10:00
|
|
|
jssrcnote *sn;
|
2025-02-03 12:35:24 +10:00
|
|
|
JSSecurityCallbacks *callbacks;
|
2025-03-19 21:25:58 +10:00
|
|
|
uint32 scriptBits = 0;
|
2018-09-08 18:08:48 +08:00
|
|
|
|
2025-03-19 21:25:58 +10:00
|
|
|
JSContext *cx = xdr->cx;
|
|
|
|
|
JSScript *script = *scriptp;
|
|
|
|
|
nsrcnotes = ntrynotes = natoms = nobjects = nregexps = nconsts = 0;
|
2018-09-08 18:08:48 +08:00
|
|
|
filenameWasSaved = JS_FALSE;
|
2025-03-19 21:25:58 +10:00
|
|
|
jssrcnote *notes = NULL;
|
|
|
|
|
|
|
|
|
|
/* Should not XDR scripts optimized for a single global object. */
|
|
|
|
|
JS_ASSERT_IF(script, !JSScript::isValidOffset(script->globalsOffset));
|
2018-09-08 18:08:48 +08:00
|
|
|
|
2025-03-19 21:25:58 +10:00
|
|
|
uint32 magic;
|
2018-09-08 18:08:48 +08:00
|
|
|
if (xdr->mode == JSXDR_ENCODE)
|
|
|
|
|
magic = JSXDR_MAGIC_SCRIPT_CURRENT;
|
|
|
|
|
if (!JS_XDRUint32(xdr, &magic))
|
|
|
|
|
return JS_FALSE;
|
2023-07-12 13:27:26 +10:00
|
|
|
if (magic != JSXDR_MAGIC_SCRIPT_CURRENT) {
|
|
|
|
|
/* We do not provide binary compatibility with older scripts. */
|
2018-09-08 18:08:48 +08:00
|
|
|
if (!hasMagic) {
|
|
|
|
|
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL,
|
|
|
|
|
JSMSG_BAD_SCRIPT_MAGIC);
|
|
|
|
|
return JS_FALSE;
|
|
|
|
|
}
|
|
|
|
|
*hasMagic = JS_FALSE;
|
|
|
|
|
return JS_TRUE;
|
|
|
|
|
}
|
|
|
|
|
if (hasMagic)
|
|
|
|
|
*hasMagic = JS_TRUE;
|
|
|
|
|
|
2025-03-19 21:25:58 +10:00
|
|
|
/* XDR arguments, local vars, and upvars. */
|
|
|
|
|
uint16 nargs, nvars, nupvars;
|
|
|
|
|
#if defined(DEBUG) || defined(__GNUC__) /* quell GCC overwarning */
|
|
|
|
|
nargs = nvars = nupvars = Bindings::BINDING_COUNT_LIMIT;
|
|
|
|
|
#endif
|
|
|
|
|
uint32 argsVars, paddingUpvars;
|
|
|
|
|
if (xdr->mode == JSXDR_ENCODE) {
|
|
|
|
|
nargs = script->bindings.countArgs();
|
|
|
|
|
nvars = script->bindings.countVars();
|
|
|
|
|
nupvars = script->bindings.countUpvars();
|
|
|
|
|
argsVars = (nargs << 16) | nvars;
|
|
|
|
|
paddingUpvars = nupvars;
|
|
|
|
|
}
|
|
|
|
|
if (!JS_XDRUint32(xdr, &argsVars) || !JS_XDRUint32(xdr, &paddingUpvars))
|
|
|
|
|
return false;
|
|
|
|
|
if (xdr->mode == JSXDR_DECODE) {
|
|
|
|
|
nargs = argsVars >> 16;
|
|
|
|
|
nvars = argsVars & 0xFFFF;
|
|
|
|
|
JS_ASSERT((paddingUpvars >> 16) == 0);
|
|
|
|
|
nupvars = paddingUpvars & 0xFFFF;
|
|
|
|
|
}
|
|
|
|
|
JS_ASSERT(nargs != Bindings::BINDING_COUNT_LIMIT);
|
|
|
|
|
JS_ASSERT(nvars != Bindings::BINDING_COUNT_LIMIT);
|
|
|
|
|
JS_ASSERT(nupvars != Bindings::BINDING_COUNT_LIMIT);
|
|
|
|
|
|
|
|
|
|
Bindings bindings(cx);
|
|
|
|
|
AutoBindingsRooter rooter(cx, bindings);
|
|
|
|
|
uint32 nameCount = nargs + nvars + nupvars;
|
|
|
|
|
if (nameCount > 0) {
|
|
|
|
|
struct AutoMark {
|
|
|
|
|
JSArenaPool * const pool;
|
|
|
|
|
void * const mark;
|
|
|
|
|
AutoMark(JSArenaPool *pool) : pool(pool), mark(JS_ARENA_MARK(pool)) { }
|
|
|
|
|
~AutoMark() {
|
|
|
|
|
JS_ARENA_RELEASE(pool, mark);
|
|
|
|
|
}
|
|
|
|
|
} automark(&cx->tempPool);
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* To xdr the names we prefix the names with a bitmap descriptor and
|
|
|
|
|
* then xdr the names as strings. For argument names (indexes below
|
|
|
|
|
* nargs) the corresponding bit in the bitmap is unset when the name
|
|
|
|
|
* is null. Such null names are not encoded or decoded. For variable
|
|
|
|
|
* names (indexes starting from nargs) bitmap's bit is set when the
|
|
|
|
|
* name is declared as const, not as ordinary var.
|
|
|
|
|
* */
|
|
|
|
|
uintN bitmapLength = JS_HOWMANY(nameCount, JS_BITS_PER_UINT32);
|
|
|
|
|
uint32 *bitmap;
|
|
|
|
|
JS_ARENA_ALLOCATE_CAST(bitmap, uint32 *, &cx->tempPool,
|
|
|
|
|
bitmapLength * sizeof *bitmap);
|
|
|
|
|
if (!bitmap) {
|
|
|
|
|
js_ReportOutOfScriptQuota(cx);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
jsuword *names;
|
2025-02-05 12:40:54 +10:00
|
|
|
if (xdr->mode == JSXDR_ENCODE) {
|
2025-03-19 21:25:58 +10:00
|
|
|
names = script->bindings.getLocalNameArray(cx, &cx->tempPool);
|
|
|
|
|
if (!names)
|
|
|
|
|
return false;
|
|
|
|
|
PodZero(bitmap, bitmapLength);
|
|
|
|
|
for (uintN i = 0; i < nameCount; i++) {
|
|
|
|
|
if (i < nargs
|
|
|
|
|
? JS_LOCAL_NAME_TO_ATOM(names[i]) != NULL
|
|
|
|
|
: JS_LOCAL_NAME_IS_CONST(names[i]))
|
|
|
|
|
{
|
|
|
|
|
bitmap[i >> JS_BITS_PER_UINT32_LOG2] |= JS_BIT(i & (JS_BITS_PER_UINT32 - 1));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#ifdef __GNUC__
|
|
|
|
|
else {
|
|
|
|
|
names = NULL; /* quell GCC uninitialized warning */
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
for (uintN i = 0; i < bitmapLength; ++i) {
|
|
|
|
|
if (!JS_XDRUint32(xdr, &bitmap[i]))
|
|
|
|
|
return false;
|
2025-02-05 12:40:54 +10:00
|
|
|
}
|
|
|
|
|
|
2025-03-19 21:25:58 +10:00
|
|
|
for (uintN i = 0; i < nameCount; i++) {
|
|
|
|
|
if (i < nargs &&
|
|
|
|
|
!(bitmap[i >> JS_BITS_PER_UINT32_LOG2] & JS_BIT(i & (JS_BITS_PER_UINT32 - 1))))
|
|
|
|
|
{
|
|
|
|
|
if (xdr->mode == JSXDR_DECODE) {
|
|
|
|
|
uint16 dummy;
|
|
|
|
|
if (!bindings.addDestructuring(cx, &dummy))
|
|
|
|
|
return false;
|
|
|
|
|
} else {
|
|
|
|
|
JS_ASSERT(!JS_LOCAL_NAME_TO_ATOM(names[i]));
|
|
|
|
|
}
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
JSAtom *name;
|
|
|
|
|
if (xdr->mode == JSXDR_ENCODE)
|
|
|
|
|
name = JS_LOCAL_NAME_TO_ATOM(names[i]);
|
|
|
|
|
if (!js_XDRAtom(xdr, &name))
|
|
|
|
|
return false;
|
|
|
|
|
if (xdr->mode == JSXDR_DECODE) {
|
|
|
|
|
BindingKind kind = (i < nargs)
|
|
|
|
|
? ARGUMENT
|
|
|
|
|
: (i < uintN(nargs + nvars))
|
|
|
|
|
? (bitmap[i >> JS_BITS_PER_UINT32_LOG2] &
|
|
|
|
|
JS_BIT(i & (JS_BITS_PER_UINT32 - 1))
|
|
|
|
|
? CONSTANT
|
|
|
|
|
: VARIABLE)
|
|
|
|
|
: UPVAR;
|
|
|
|
|
if (!bindings.add(cx, name, kind))
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2025-02-05 12:40:54 +10:00
|
|
|
}
|
|
|
|
|
|
2025-03-19 21:25:58 +10:00
|
|
|
if (xdr->mode == JSXDR_DECODE)
|
|
|
|
|
bindings.makeImmutable();
|
2025-02-05 12:40:54 +10:00
|
|
|
}
|
|
|
|
|
|
2025-03-19 21:25:58 +10:00
|
|
|
if (xdr->mode == JSXDR_ENCODE)
|
|
|
|
|
length = script->length;
|
|
|
|
|
if (!JS_XDRUint32(xdr, &length))
|
|
|
|
|
return JS_FALSE;
|
|
|
|
|
|
2018-09-08 18:08:48 +08:00
|
|
|
if (xdr->mode == JSXDR_ENCODE) {
|
2025-02-05 12:40:54 +10:00
|
|
|
prologLength = script->main - script->code;
|
2025-03-19 21:25:58 +10:00
|
|
|
JS_ASSERT(script->getVersion() != JSVERSION_UNKNOWN);
|
|
|
|
|
version = (uint32)script->getVersion() | (script->nfixed << 16);
|
2018-09-08 18:08:48 +08:00
|
|
|
lineno = (uint32)script->lineno;
|
2025-02-03 12:35:24 +10:00
|
|
|
nslots = (uint32)script->nslots;
|
2025-02-05 12:40:54 +10:00
|
|
|
nslots = (uint32)((script->staticLevel << 16) | script->nslots);
|
2023-07-12 13:27:26 +10:00
|
|
|
natoms = (uint32)script->atomMap.length;
|
2018-09-08 18:08:48 +08:00
|
|
|
|
|
|
|
|
/* Count the srcnotes, keeping notes pointing at the first one. */
|
2025-02-05 12:40:54 +10:00
|
|
|
notes = script->notes();
|
2018-09-08 18:08:48 +08:00
|
|
|
for (sn = notes; !SN_IS_TERMINATOR(sn); sn = SN_NEXT(sn))
|
|
|
|
|
continue;
|
2025-02-05 12:40:54 +10:00
|
|
|
nsrcnotes = sn - notes;
|
2018-09-08 18:08:48 +08:00
|
|
|
nsrcnotes++; /* room for the terminator */
|
|
|
|
|
|
2025-03-19 21:25:58 +10:00
|
|
|
if (JSScript::isValidOffset(script->objectsOffset))
|
2025-02-05 12:40:54 +10:00
|
|
|
nobjects = script->objects()->length;
|
2025-03-19 21:25:58 +10:00
|
|
|
if (JSScript::isValidOffset(script->upvarsOffset))
|
|
|
|
|
JS_ASSERT(script->bindings.countUpvars() == script->upvars()->length);
|
|
|
|
|
if (JSScript::isValidOffset(script->regexpsOffset))
|
2025-02-05 12:40:54 +10:00
|
|
|
nregexps = script->regexps()->length;
|
2025-03-19 21:25:58 +10:00
|
|
|
if (JSScript::isValidOffset(script->trynotesOffset))
|
2025-02-05 12:40:54 +10:00
|
|
|
ntrynotes = script->trynotes()->length;
|
2025-03-19 21:25:58 +10:00
|
|
|
if (JSScript::isValidOffset(script->constOffset))
|
|
|
|
|
nconsts = script->consts()->length;
|
|
|
|
|
|
|
|
|
|
nClosedArgs = script->nClosedArgs;
|
|
|
|
|
nClosedVars = script->nClosedVars;
|
|
|
|
|
encodedClosedCount = (nClosedArgs << 16) | nClosedVars;
|
|
|
|
|
|
|
|
|
|
if (script->noScriptRval)
|
|
|
|
|
scriptBits |= (1 << NoScriptRval);
|
|
|
|
|
if (script->savedCallerFun)
|
|
|
|
|
scriptBits |= (1 << SavedCallerFun);
|
|
|
|
|
if (script->hasSharps)
|
|
|
|
|
scriptBits |= (1 << HasSharps);
|
|
|
|
|
if (script->strictModeCode)
|
|
|
|
|
scriptBits |= (1 << StrictModeCode);
|
|
|
|
|
if (script->usesEval)
|
|
|
|
|
scriptBits |= (1 << UsesEval);
|
|
|
|
|
if (script->usesArguments)
|
|
|
|
|
scriptBits |= (1 << UsesArguments);
|
|
|
|
|
JS_ASSERT(!script->compileAndGo);
|
|
|
|
|
JS_ASSERT(!script->hasSingletons);
|
2018-09-08 18:08:48 +08:00
|
|
|
}
|
|
|
|
|
|
2023-07-12 13:27:26 +10:00
|
|
|
if (!JS_XDRUint32(xdr, &prologLength))
|
|
|
|
|
return JS_FALSE;
|
|
|
|
|
if (!JS_XDRUint32(xdr, &version))
|
|
|
|
|
return JS_FALSE;
|
2018-09-08 18:08:48 +08:00
|
|
|
|
2023-07-12 13:27:26 +10:00
|
|
|
/*
|
2025-03-19 21:25:58 +10:00
|
|
|
* To fuse allocations, we need srcnote, atom, objects, regexp, and trynote
|
|
|
|
|
* counts early.
|
2023-07-12 13:27:26 +10:00
|
|
|
*/
|
|
|
|
|
if (!JS_XDRUint32(xdr, &natoms))
|
|
|
|
|
return JS_FALSE;
|
|
|
|
|
if (!JS_XDRUint32(xdr, &nsrcnotes))
|
|
|
|
|
return JS_FALSE;
|
|
|
|
|
if (!JS_XDRUint32(xdr, &ntrynotes))
|
|
|
|
|
return JS_FALSE;
|
|
|
|
|
if (!JS_XDRUint32(xdr, &nobjects))
|
|
|
|
|
return JS_FALSE;
|
|
|
|
|
if (!JS_XDRUint32(xdr, &nregexps))
|
|
|
|
|
return JS_FALSE;
|
2025-03-19 21:25:58 +10:00
|
|
|
if (!JS_XDRUint32(xdr, &nconsts))
|
|
|
|
|
return JS_FALSE;
|
|
|
|
|
if (!JS_XDRUint32(xdr, &encodedClosedCount))
|
|
|
|
|
return JS_FALSE;
|
|
|
|
|
if (!JS_XDRUint32(xdr, &scriptBits))
|
|
|
|
|
return JS_FALSE;
|
2018-09-08 18:08:48 +08:00
|
|
|
|
2025-02-05 12:40:54 +10:00
|
|
|
AutoScriptRooter tvr(cx, NULL);
|
|
|
|
|
|
2018-09-08 18:08:48 +08:00
|
|
|
if (xdr->mode == JSXDR_DECODE) {
|
2025-03-19 21:25:58 +10:00
|
|
|
nClosedArgs = encodedClosedCount >> 16;
|
|
|
|
|
nClosedVars = encodedClosedCount & 0xFFFF;
|
|
|
|
|
|
|
|
|
|
/* Note: version is packed into the 32b space with another 16b value. */
|
|
|
|
|
JSVersion version_ = JSVersion(version & JS_BITMASK(16));
|
|
|
|
|
JS_ASSERT((version_ & VersionFlags::FULL_MASK) == uintN(version_));
|
|
|
|
|
script = JSScript::NewScript(cx, length, nsrcnotes, natoms, nobjects, nupvars,
|
|
|
|
|
nregexps, ntrynotes, nconsts, 0, nClosedArgs,
|
|
|
|
|
nClosedVars, version_);
|
2018-09-08 18:08:48 +08:00
|
|
|
if (!script)
|
|
|
|
|
return JS_FALSE;
|
2023-07-12 13:27:26 +10:00
|
|
|
|
2025-03-19 21:25:58 +10:00
|
|
|
script->bindings.transfer(cx, &bindings);
|
|
|
|
|
|
2023-07-12 13:27:26 +10:00
|
|
|
script->main += prologLength;
|
2025-02-05 12:40:54 +10:00
|
|
|
script->nfixed = uint16(version >> 16);
|
2023-07-12 13:27:26 +10:00
|
|
|
|
|
|
|
|
/* If we know nsrcnotes, we allocated space for notes in script. */
|
2025-02-05 12:40:54 +10:00
|
|
|
notes = script->notes();
|
2018-09-08 18:08:48 +08:00
|
|
|
*scriptp = script;
|
2025-02-05 12:40:54 +10:00
|
|
|
tvr.setScript(script);
|
2025-03-19 21:25:58 +10:00
|
|
|
|
|
|
|
|
if (scriptBits & (1 << NoScriptRval))
|
|
|
|
|
script->noScriptRval = true;
|
|
|
|
|
if (scriptBits & (1 << SavedCallerFun))
|
|
|
|
|
script->savedCallerFun = true;
|
|
|
|
|
if (scriptBits & (1 << HasSharps))
|
|
|
|
|
script->hasSharps = true;
|
|
|
|
|
if (scriptBits & (1 << StrictModeCode))
|
|
|
|
|
script->strictModeCode = true;
|
|
|
|
|
if (scriptBits & (1 << UsesEval))
|
|
|
|
|
script->usesEval = true;
|
|
|
|
|
if (scriptBits & (1 << UsesArguments))
|
|
|
|
|
script->usesArguments = true;
|
2018-09-08 18:08:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
2023-07-12 13:27:26 +10:00
|
|
|
* Control hereafter must goto error on failure, in order for the
|
|
|
|
|
* DECODE case to destroy script.
|
2018-09-08 18:08:48 +08:00
|
|
|
*/
|
Numerous changes with focus on feature and stability parity across Windows, Linux and MacOS platforms
Added new Makefile that handles compiling UOX3 and Spidermonkey on both Linux and MacOS (punt)
Added VS solution (SpiderMonkey.sln) and VC++ project files for compiling SpiderMonkey on Windows (Xuri)
Updated SpiderMonkey from v1.6.0 to v1.7.0
Added optimization flag -O2 for release build in CMakeLists.txt in project root (Xuri)
Added StringUtility file with general common string manipulation functions (punt)
Updated RandomNum function to use a "seedless" random number generator from C++11 instead of the old C rand() function. (punt)
Overall code cleanup to remove/replace platform-dependent code (punt)
Replaced potentially unsafe usage of C string stuff like sprintf, vsprintf, vsnprintf, strncat, strcpy and strlen throughout the code with calls to a format() function containing only a single, safe use of vsnprintf, ensuring there's a single place of failure if there's anything to fix and and making it easy to potentially replace this with std::format from C++20 when the time comes. (punt)
Replaced usage of char in many places with std::string (punt)
Started process of replacing UString usage with functions provided through StringUtility instead (punt)
Replaced platform specific fileIO handling in Windows/Linux with cross-platform C++17 standard std::filesystem (punt)
Replaced platform specific time handling by using cross-platform chrono library (punt)
Removed UOX namespace to reduce complexity (punt)
Elimitated template code approach to singletons for more modern c++ constructs, removing dependices in the process (punt)
Removed ODBC support; it hasn't been touched since the initial implementation in 2008, and there is a lack of someone to maintain the code. (punt)
Removed some platform specific files like uoxlinux.h, which is no longer required (punt)
Removed legacy crash protection code, and removed support for cluox (punt)
Removed legacy "support" for Borland compiler (punt)
Removed legacy VC++ 6 Workspace/Project files, VS2005 Solution/Project files, as these are no longer supported (Xuri)
Removed legacy BUILD folder with outdated compilation instructions (Xuri)
Removed old Changelog file (merged into Changelog.txt) (Xuri)
Fixed a pointer bug for items in multis on world load (punt)
Fixed a dictionary related issue that caused segmentation faults on Linux/MacOS (punt)
Fixed an issue with callbacks to JS scripts that caused segmentation faults on Linux/MacOS (punt)
Paths in uox.ini should now load properly on all platforms regardless of whether those paths use slashes or backslashes, and whether or not they end in a slash/backslash. (punt)
Moved to c++17 style of threading, and got rid of threadsafeobject.cpp/h (punt)
Replaced parsing of UOX.INI tags with a system that's more easily maintainable (punt)
Added some new commands to js/commands/custom/misc-cmd.js (Xuri)
cont // Targeted item will be made a container, set to nondecay and movable 2
endfight // Targeted character (and character being fought) will stop fighting
getmulti // Get multiObject for targeted item
finditem // Find item at layer X
movespeed // Set movement speed of target player (0x0 Normal, 0x1 Mounted, 0x2 Slow (walk only), 0x3 Hybrid ("jog"?), 0x4 Frozen)
Added new HTML based documentation in docs folder, and removed many old legacy docs that are either incorporated into this document already or no longer relevant for the current UOX3 version (Xuri)
Co-Authored-By: Charles Kerr <punt1959@users.noreply.github.com>
2020-09-07 18:09:55 +08:00
|
|
|
oldscript = xdr->script;
|
2023-07-12 13:27:26 +10:00
|
|
|
code = script->code;
|
|
|
|
|
if (xdr->mode == JSXDR_ENCODE) {
|
|
|
|
|
code = js_UntrapScriptCode(cx, script);
|
|
|
|
|
if (!code)
|
|
|
|
|
goto error;
|
2018-09-08 18:08:48 +08:00
|
|
|
}
|
|
|
|
|
|
2023-07-12 13:27:26 +10:00
|
|
|
xdr->script = script;
|
|
|
|
|
ok = JS_XDRBytes(xdr, (char *) code, length * sizeof(jsbytecode));
|
Numerous changes with focus on feature and stability parity across Windows, Linux and MacOS platforms
Added new Makefile that handles compiling UOX3 and Spidermonkey on both Linux and MacOS (punt)
Added VS solution (SpiderMonkey.sln) and VC++ project files for compiling SpiderMonkey on Windows (Xuri)
Updated SpiderMonkey from v1.6.0 to v1.7.0
Added optimization flag -O2 for release build in CMakeLists.txt in project root (Xuri)
Added StringUtility file with general common string manipulation functions (punt)
Updated RandomNum function to use a "seedless" random number generator from C++11 instead of the old C rand() function. (punt)
Overall code cleanup to remove/replace platform-dependent code (punt)
Replaced potentially unsafe usage of C string stuff like sprintf, vsprintf, vsnprintf, strncat, strcpy and strlen throughout the code with calls to a format() function containing only a single, safe use of vsnprintf, ensuring there's a single place of failure if there's anything to fix and and making it easy to potentially replace this with std::format from C++20 when the time comes. (punt)
Replaced usage of char in many places with std::string (punt)
Started process of replacing UString usage with functions provided through StringUtility instead (punt)
Replaced platform specific fileIO handling in Windows/Linux with cross-platform C++17 standard std::filesystem (punt)
Replaced platform specific time handling by using cross-platform chrono library (punt)
Removed UOX namespace to reduce complexity (punt)
Elimitated template code approach to singletons for more modern c++ constructs, removing dependices in the process (punt)
Removed ODBC support; it hasn't been touched since the initial implementation in 2008, and there is a lack of someone to maintain the code. (punt)
Removed some platform specific files like uoxlinux.h, which is no longer required (punt)
Removed legacy crash protection code, and removed support for cluox (punt)
Removed legacy "support" for Borland compiler (punt)
Removed legacy VC++ 6 Workspace/Project files, VS2005 Solution/Project files, as these are no longer supported (Xuri)
Removed legacy BUILD folder with outdated compilation instructions (Xuri)
Removed old Changelog file (merged into Changelog.txt) (Xuri)
Fixed a pointer bug for items in multis on world load (punt)
Fixed a dictionary related issue that caused segmentation faults on Linux/MacOS (punt)
Fixed an issue with callbacks to JS scripts that caused segmentation faults on Linux/MacOS (punt)
Paths in uox.ini should now load properly on all platforms regardless of whether those paths use slashes or backslashes, and whether or not they end in a slash/backslash. (punt)
Moved to c++17 style of threading, and got rid of threadsafeobject.cpp/h (punt)
Replaced parsing of UOX.INI tags with a system that's more easily maintainable (punt)
Added some new commands to js/commands/custom/misc-cmd.js (Xuri)
cont // Targeted item will be made a container, set to nondecay and movable 2
endfight // Targeted character (and character being fought) will stop fighting
getmulti // Get multiObject for targeted item
finditem // Find item at layer X
movespeed // Set movement speed of target player (0x0 Normal, 0x1 Mounted, 0x2 Slow (walk only), 0x3 Hybrid ("jog"?), 0x4 Frozen)
Added new HTML based documentation in docs folder, and removed many old legacy docs that are either incorporated into this document already or no longer relevant for the current UOX3 version (Xuri)
Co-Authored-By: Charles Kerr <punt1959@users.noreply.github.com>
2020-09-07 18:09:55 +08:00
|
|
|
|
2023-07-12 13:27:26 +10:00
|
|
|
if (code != script->code)
|
2025-02-05 12:40:54 +10:00
|
|
|
cx->free(code);
|
2023-07-12 13:27:26 +10:00
|
|
|
|
|
|
|
|
if (!ok)
|
|
|
|
|
goto error;
|
2018-09-08 18:08:48 +08:00
|
|
|
|
|
|
|
|
if (!JS_XDRBytes(xdr, (char *)notes, nsrcnotes * sizeof(jssrcnote)) ||
|
|
|
|
|
!JS_XDRCStringOrNull(xdr, (char **)&script->filename) ||
|
|
|
|
|
!JS_XDRUint32(xdr, &lineno) ||
|
2025-02-03 12:35:24 +10:00
|
|
|
!JS_XDRUint32(xdr, &nslots)) {
|
2018-09-08 18:08:48 +08:00
|
|
|
goto error;
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-03 12:35:24 +10:00
|
|
|
callbacks = JS_GetSecurityCallbacks(cx);
|
2023-07-12 13:27:26 +10:00
|
|
|
if (xdr->mode == JSXDR_ENCODE) {
|
|
|
|
|
principals = script->principals;
|
2025-02-03 12:35:24 +10:00
|
|
|
encodeable = callbacks && callbacks->principalsTranscoder;
|
2023-07-12 13:27:26 +10:00
|
|
|
if (!JS_XDRUint32(xdr, &encodeable))
|
|
|
|
|
goto error;
|
|
|
|
|
if (encodeable &&
|
2025-02-03 12:35:24 +10:00
|
|
|
!callbacks->principalsTranscoder(xdr, &principals)) {
|
2023-07-12 13:27:26 +10:00
|
|
|
goto error;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if (!JS_XDRUint32(xdr, &encodeable))
|
|
|
|
|
goto error;
|
|
|
|
|
if (encodeable) {
|
2025-02-03 12:35:24 +10:00
|
|
|
if (!(callbacks && callbacks->principalsTranscoder)) {
|
2023-07-12 13:27:26 +10:00
|
|
|
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL,
|
|
|
|
|
JSMSG_CANT_DECODE_PRINCIPALS);
|
2018-09-08 18:08:48 +08:00
|
|
|
goto error;
|
|
|
|
|
}
|
2025-02-03 12:35:24 +10:00
|
|
|
if (!callbacks->principalsTranscoder(xdr, &principals))
|
2018-09-08 18:08:48 +08:00
|
|
|
goto error;
|
2023-07-12 13:27:26 +10:00
|
|
|
script->principals = principals;
|
2018-09-08 18:08:48 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (xdr->mode == JSXDR_DECODE) {
|
|
|
|
|
const char *filename = script->filename;
|
|
|
|
|
if (filename) {
|
|
|
|
|
filename = js_SaveScriptFilename(cx, filename);
|
|
|
|
|
if (!filename)
|
|
|
|
|
goto error;
|
2025-02-05 12:40:54 +10:00
|
|
|
cx->free((void *) script->filename);
|
2018-09-08 18:08:48 +08:00
|
|
|
script->filename = filename;
|
|
|
|
|
filenameWasSaved = JS_TRUE;
|
|
|
|
|
}
|
|
|
|
|
script->lineno = (uintN)lineno;
|
2025-02-03 12:35:24 +10:00
|
|
|
script->nslots = (uint16)nslots;
|
2025-02-05 12:40:54 +10:00
|
|
|
script->staticLevel = (uint16)(nslots >> 16);
|
2025-03-19 21:25:58 +10:00
|
|
|
|
2018-09-08 18:08:48 +08:00
|
|
|
}
|
|
|
|
|
|
2023-07-12 13:27:26 +10:00
|
|
|
for (i = 0; i != natoms; ++i) {
|
|
|
|
|
if (!js_XDRAtom(xdr, &script->atomMap.vector[i]))
|
|
|
|
|
goto error;
|
|
|
|
|
}
|
2018-09-08 18:08:48 +08:00
|
|
|
|
2023-07-12 13:27:26 +10:00
|
|
|
/*
|
|
|
|
|
* Here looping from 0-to-length to xdr objects is essential. It ensures
|
2025-02-03 12:35:24 +10:00
|
|
|
* that block objects from the script->objects array will be written and
|
2025-02-05 12:40:54 +10:00
|
|
|
* restored in the outer-to-inner order. js_XDRBlockObject relies on this
|
|
|
|
|
* to restore the parent chain.
|
2023-07-12 13:27:26 +10:00
|
|
|
*/
|
|
|
|
|
for (i = 0; i != nobjects; ++i) {
|
2025-02-05 12:40:54 +10:00
|
|
|
JSObject **objp = &script->objects()->vector[i];
|
|
|
|
|
uint32 isBlock;
|
|
|
|
|
if (xdr->mode == JSXDR_ENCODE) {
|
2025-03-19 21:25:58 +10:00
|
|
|
Class *clasp = (*objp)->getClass();
|
2025-02-05 12:40:54 +10:00
|
|
|
JS_ASSERT(clasp == &js_FunctionClass ||
|
|
|
|
|
clasp == &js_BlockClass);
|
|
|
|
|
isBlock = (clasp == &js_BlockClass) ? 1 : 0;
|
|
|
|
|
}
|
|
|
|
|
if (!JS_XDRUint32(xdr, &isBlock))
|
2018-09-08 18:08:48 +08:00
|
|
|
goto error;
|
2025-02-05 12:40:54 +10:00
|
|
|
if (isBlock == 0) {
|
|
|
|
|
if (!js_XDRFunctionObject(xdr, objp))
|
|
|
|
|
goto error;
|
|
|
|
|
} else {
|
|
|
|
|
JS_ASSERT(isBlock == 1);
|
|
|
|
|
if (!js_XDRBlockObject(xdr, objp))
|
|
|
|
|
goto error;
|
|
|
|
|
}
|
2023-07-12 13:27:26 +10:00
|
|
|
}
|
2025-02-03 12:35:24 +10:00
|
|
|
for (i = 0; i != nupvars; ++i) {
|
2025-03-19 21:25:58 +10:00
|
|
|
if (!JS_XDRUint32(xdr, reinterpret_cast<uint32 *>(&script->upvars()->vector[i])))
|
2025-02-03 12:35:24 +10:00
|
|
|
goto error;
|
|
|
|
|
}
|
2023-07-12 13:27:26 +10:00
|
|
|
for (i = 0; i != nregexps; ++i) {
|
2025-02-05 12:40:54 +10:00
|
|
|
if (!js_XDRRegExpObject(xdr, &script->regexps()->vector[i]))
|
2023-07-12 13:27:26 +10:00
|
|
|
goto error;
|
|
|
|
|
}
|
2025-03-19 21:25:58 +10:00
|
|
|
for (i = 0; i != nClosedArgs; ++i) {
|
|
|
|
|
if (!JS_XDRUint32(xdr, &script->closedSlots[i]))
|
|
|
|
|
goto error;
|
|
|
|
|
}
|
|
|
|
|
for (i = 0; i != nClosedVars; ++i) {
|
|
|
|
|
if (!JS_XDRUint32(xdr, &script->closedSlots[nClosedArgs + i]))
|
|
|
|
|
goto error;
|
|
|
|
|
}
|
2023-07-12 13:27:26 +10:00
|
|
|
|
|
|
|
|
if (ntrynotes != 0) {
|
|
|
|
|
/*
|
|
|
|
|
* We combine tn->kind and tn->stackDepth when serializing as XDR is not
|
|
|
|
|
* efficient when serializing small integer types.
|
|
|
|
|
*/
|
|
|
|
|
JSTryNote *tn, *tnfirst;
|
|
|
|
|
uint32 kindAndDepth;
|
|
|
|
|
JS_STATIC_ASSERT(sizeof(tn->kind) == sizeof(uint8));
|
|
|
|
|
JS_STATIC_ASSERT(sizeof(tn->stackDepth) == sizeof(uint16));
|
|
|
|
|
|
2025-02-05 12:40:54 +10:00
|
|
|
tnfirst = script->trynotes()->vector;
|
|
|
|
|
JS_ASSERT(script->trynotes()->length == ntrynotes);
|
2023-07-12 13:27:26 +10:00
|
|
|
tn = tnfirst + ntrynotes;
|
|
|
|
|
do {
|
|
|
|
|
--tn;
|
|
|
|
|
if (xdr->mode == JSXDR_ENCODE) {
|
|
|
|
|
kindAndDepth = ((uint32)tn->kind << 16)
|
|
|
|
|
| (uint32)tn->stackDepth;
|
|
|
|
|
}
|
|
|
|
|
if (!JS_XDRUint32(xdr, &kindAndDepth) ||
|
|
|
|
|
!JS_XDRUint32(xdr, &tn->start) ||
|
|
|
|
|
!JS_XDRUint32(xdr, &tn->length)) {
|
|
|
|
|
goto error;
|
|
|
|
|
}
|
|
|
|
|
if (xdr->mode == JSXDR_DECODE) {
|
|
|
|
|
tn->kind = (uint8)(kindAndDepth >> 16);
|
|
|
|
|
tn->stackDepth = (uint16)kindAndDepth;
|
|
|
|
|
}
|
|
|
|
|
} while (tn != tnfirst);
|
2018-09-08 18:08:48 +08:00
|
|
|
}
|
Numerous changes with focus on feature and stability parity across Windows, Linux and MacOS platforms
Added new Makefile that handles compiling UOX3 and Spidermonkey on both Linux and MacOS (punt)
Added VS solution (SpiderMonkey.sln) and VC++ project files for compiling SpiderMonkey on Windows (Xuri)
Updated SpiderMonkey from v1.6.0 to v1.7.0
Added optimization flag -O2 for release build in CMakeLists.txt in project root (Xuri)
Added StringUtility file with general common string manipulation functions (punt)
Updated RandomNum function to use a "seedless" random number generator from C++11 instead of the old C rand() function. (punt)
Overall code cleanup to remove/replace platform-dependent code (punt)
Replaced potentially unsafe usage of C string stuff like sprintf, vsprintf, vsnprintf, strncat, strcpy and strlen throughout the code with calls to a format() function containing only a single, safe use of vsnprintf, ensuring there's a single place of failure if there's anything to fix and and making it easy to potentially replace this with std::format from C++20 when the time comes. (punt)
Replaced usage of char in many places with std::string (punt)
Started process of replacing UString usage with functions provided through StringUtility instead (punt)
Replaced platform specific fileIO handling in Windows/Linux with cross-platform C++17 standard std::filesystem (punt)
Replaced platform specific time handling by using cross-platform chrono library (punt)
Removed UOX namespace to reduce complexity (punt)
Elimitated template code approach to singletons for more modern c++ constructs, removing dependices in the process (punt)
Removed ODBC support; it hasn't been touched since the initial implementation in 2008, and there is a lack of someone to maintain the code. (punt)
Removed some platform specific files like uoxlinux.h, which is no longer required (punt)
Removed legacy crash protection code, and removed support for cluox (punt)
Removed legacy "support" for Borland compiler (punt)
Removed legacy VC++ 6 Workspace/Project files, VS2005 Solution/Project files, as these are no longer supported (Xuri)
Removed legacy BUILD folder with outdated compilation instructions (Xuri)
Removed old Changelog file (merged into Changelog.txt) (Xuri)
Fixed a pointer bug for items in multis on world load (punt)
Fixed a dictionary related issue that caused segmentation faults on Linux/MacOS (punt)
Fixed an issue with callbacks to JS scripts that caused segmentation faults on Linux/MacOS (punt)
Paths in uox.ini should now load properly on all platforms regardless of whether those paths use slashes or backslashes, and whether or not they end in a slash/backslash. (punt)
Moved to c++17 style of threading, and got rid of threadsafeobject.cpp/h (punt)
Replaced parsing of UOX.INI tags with a system that's more easily maintainable (punt)
Added some new commands to js/commands/custom/misc-cmd.js (Xuri)
cont // Targeted item will be made a container, set to nondecay and movable 2
endfight // Targeted character (and character being fought) will stop fighting
getmulti // Get multiObject for targeted item
finditem // Find item at layer X
movespeed // Set movement speed of target player (0x0 Normal, 0x1 Mounted, 0x2 Slow (walk only), 0x3 Hybrid ("jog"?), 0x4 Frozen)
Added new HTML based documentation in docs folder, and removed many old legacy docs that are either incorporated into this document already or no longer relevant for the current UOX3 version (Xuri)
Co-Authored-By: Charles Kerr <punt1959@users.noreply.github.com>
2020-09-07 18:09:55 +08:00
|
|
|
|
2025-03-19 21:25:58 +10:00
|
|
|
for (i = 0; i != nconsts; ++i) {
|
|
|
|
|
if (!JS_XDRValue(xdr, Jsvalify(&script->consts()->vector[i])))
|
|
|
|
|
goto error;
|
|
|
|
|
}
|
|
|
|
|
|
Numerous changes with focus on feature and stability parity across Windows, Linux and MacOS platforms
Added new Makefile that handles compiling UOX3 and Spidermonkey on both Linux and MacOS (punt)
Added VS solution (SpiderMonkey.sln) and VC++ project files for compiling SpiderMonkey on Windows (Xuri)
Updated SpiderMonkey from v1.6.0 to v1.7.0
Added optimization flag -O2 for release build in CMakeLists.txt in project root (Xuri)
Added StringUtility file with general common string manipulation functions (punt)
Updated RandomNum function to use a "seedless" random number generator from C++11 instead of the old C rand() function. (punt)
Overall code cleanup to remove/replace platform-dependent code (punt)
Replaced potentially unsafe usage of C string stuff like sprintf, vsprintf, vsnprintf, strncat, strcpy and strlen throughout the code with calls to a format() function containing only a single, safe use of vsnprintf, ensuring there's a single place of failure if there's anything to fix and and making it easy to potentially replace this with std::format from C++20 when the time comes. (punt)
Replaced usage of char in many places with std::string (punt)
Started process of replacing UString usage with functions provided through StringUtility instead (punt)
Replaced platform specific fileIO handling in Windows/Linux with cross-platform C++17 standard std::filesystem (punt)
Replaced platform specific time handling by using cross-platform chrono library (punt)
Removed UOX namespace to reduce complexity (punt)
Elimitated template code approach to singletons for more modern c++ constructs, removing dependices in the process (punt)
Removed ODBC support; it hasn't been touched since the initial implementation in 2008, and there is a lack of someone to maintain the code. (punt)
Removed some platform specific files like uoxlinux.h, which is no longer required (punt)
Removed legacy crash protection code, and removed support for cluox (punt)
Removed legacy "support" for Borland compiler (punt)
Removed legacy VC++ 6 Workspace/Project files, VS2005 Solution/Project files, as these are no longer supported (Xuri)
Removed legacy BUILD folder with outdated compilation instructions (Xuri)
Removed old Changelog file (merged into Changelog.txt) (Xuri)
Fixed a pointer bug for items in multis on world load (punt)
Fixed a dictionary related issue that caused segmentation faults on Linux/MacOS (punt)
Fixed an issue with callbacks to JS scripts that caused segmentation faults on Linux/MacOS (punt)
Paths in uox.ini should now load properly on all platforms regardless of whether those paths use slashes or backslashes, and whether or not they end in a slash/backslash. (punt)
Moved to c++17 style of threading, and got rid of threadsafeobject.cpp/h (punt)
Replaced parsing of UOX.INI tags with a system that's more easily maintainable (punt)
Added some new commands to js/commands/custom/misc-cmd.js (Xuri)
cont // Targeted item will be made a container, set to nondecay and movable 2
endfight // Targeted character (and character being fought) will stop fighting
getmulti // Get multiObject for targeted item
finditem // Find item at layer X
movespeed // Set movement speed of target player (0x0 Normal, 0x1 Mounted, 0x2 Slow (walk only), 0x3 Hybrid ("jog"?), 0x4 Frozen)
Added new HTML based documentation in docs folder, and removed many old legacy docs that are either incorporated into this document already or no longer relevant for the current UOX3 version (Xuri)
Co-Authored-By: Charles Kerr <punt1959@users.noreply.github.com>
2020-09-07 18:09:55 +08:00
|
|
|
xdr->script = oldscript;
|
2018-09-08 18:08:48 +08:00
|
|
|
return JS_TRUE;
|
|
|
|
|
|
|
|
|
|
error:
|
|
|
|
|
if (xdr->mode == JSXDR_DECODE) {
|
|
|
|
|
if (script->filename && !filenameWasSaved) {
|
2025-02-05 12:40:54 +10:00
|
|
|
cx->free((void *) script->filename);
|
2018-09-08 18:08:48 +08:00
|
|
|
script->filename = NULL;
|
|
|
|
|
}
|
|
|
|
|
js_DestroyScript(cx, script);
|
|
|
|
|
*scriptp = NULL;
|
|
|
|
|
}
|
2023-07-12 13:27:26 +10:00
|
|
|
xdr->script = oldscript;
|
2018-09-08 18:08:48 +08:00
|
|
|
return JS_FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif /* JS_HAS_XDR */
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
script_finalize(JSContext *cx, JSObject *obj)
|
|
|
|
|
{
|
2025-02-05 12:40:54 +10:00
|
|
|
JSScript *script = (JSScript *) obj->getPrivate();
|
2018-09-08 18:08:48 +08:00
|
|
|
if (script)
|
2025-03-19 21:25:58 +10:00
|
|
|
js_DestroyScriptFromGC(cx, script);
|
2018-09-08 18:08:48 +08:00
|
|
|
}
|
|
|
|
|
|
2023-07-12 13:27:26 +10:00
|
|
|
static void
|
|
|
|
|
script_trace(JSTracer *trc, JSObject *obj)
|
2018-09-08 18:08:48 +08:00
|
|
|
{
|
2025-02-05 12:40:54 +10:00
|
|
|
JSScript *script = (JSScript *) obj->getPrivate();
|
2018-09-08 18:08:48 +08:00
|
|
|
if (script)
|
2023-07-12 13:27:26 +10:00
|
|
|
js_TraceScript(trc, script);
|
2018-09-08 18:08:48 +08:00
|
|
|
}
|
|
|
|
|
|
2025-03-19 21:25:58 +10:00
|
|
|
Class js_ScriptClass = {
|
2025-02-05 12:40:54 +10:00
|
|
|
"Script",
|
|
|
|
|
JSCLASS_HAS_PRIVATE |
|
|
|
|
|
JSCLASS_MARK_IS_TRACE | JSCLASS_HAS_CACHED_PROTO(JSProto_Object),
|
2025-03-19 21:25:58 +10:00
|
|
|
PropertyStub, /* addProperty */
|
|
|
|
|
PropertyStub, /* delProperty */
|
|
|
|
|
PropertyStub, /* getProperty */
|
|
|
|
|
StrictPropertyStub, /* setProperty */
|
|
|
|
|
EnumerateStub,
|
|
|
|
|
ResolveStub,
|
|
|
|
|
ConvertStub,
|
|
|
|
|
script_finalize,
|
|
|
|
|
NULL, /* reserved0 */
|
|
|
|
|
NULL, /* checkAccess */
|
|
|
|
|
NULL, /* call */
|
|
|
|
|
NULL, /* construct */
|
|
|
|
|
NULL, /* xdrObject */
|
|
|
|
|
NULL, /* hasInstance */
|
|
|
|
|
JS_CLASS_TRACE(script_trace)
|
2018-09-08 18:08:48 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Shared script filename management.
|
|
|
|
|
*/
|
2025-02-03 12:35:24 +10:00
|
|
|
static int
|
2018-09-08 18:08:48 +08:00
|
|
|
js_compare_strings(const void *k1, const void *k2)
|
|
|
|
|
{
|
2023-07-12 13:27:26 +10:00
|
|
|
return strcmp((const char *) k1, (const char *) k2) == 0;
|
2018-09-08 18:08:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* NB: This struct overlays JSHashEntry -- see jshash.h, do not reorganize. */
|
|
|
|
|
typedef struct ScriptFilenameEntry {
|
|
|
|
|
JSHashEntry *next; /* hash chain linkage */
|
|
|
|
|
JSHashNumber keyHash; /* key hash function result */
|
|
|
|
|
const void *key; /* ptr to filename, below */
|
|
|
|
|
uint32 flags; /* user-defined filename prefix flags */
|
|
|
|
|
JSPackedBool mark; /* GC mark flag */
|
|
|
|
|
char filename[3]; /* two or more bytes, NUL-terminated */
|
|
|
|
|
} ScriptFilenameEntry;
|
|
|
|
|
|
2025-02-03 12:35:24 +10:00
|
|
|
static void *
|
2023-07-12 13:27:26 +10:00
|
|
|
js_alloc_table_space(void *priv, size_t size)
|
|
|
|
|
{
|
2025-02-05 12:40:54 +10:00
|
|
|
return js_malloc(size);
|
2023-07-12 13:27:26 +10:00
|
|
|
}
|
|
|
|
|
|
2025-02-03 12:35:24 +10:00
|
|
|
static void
|
2025-02-05 12:40:54 +10:00
|
|
|
js_free_table_space(void *priv, void *item, size_t size)
|
2023-07-12 13:27:26 +10:00
|
|
|
{
|
2025-02-05 12:40:54 +10:00
|
|
|
js_free(item);
|
2023-07-12 13:27:26 +10:00
|
|
|
}
|
|
|
|
|
|
2025-02-03 12:35:24 +10:00
|
|
|
static JSHashEntry *
|
2018-09-08 18:08:48 +08:00
|
|
|
js_alloc_sftbl_entry(void *priv, const void *key)
|
|
|
|
|
{
|
2023-07-12 13:27:26 +10:00
|
|
|
size_t nbytes = offsetof(ScriptFilenameEntry, filename) +
|
|
|
|
|
strlen((const char *) key) + 1;
|
2018-09-08 18:08:48 +08:00
|
|
|
|
2025-02-05 12:40:54 +10:00
|
|
|
return (JSHashEntry *) js_malloc(JS_MAX(nbytes, sizeof(JSHashEntry)));
|
2018-09-08 18:08:48 +08:00
|
|
|
}
|
|
|
|
|
|
2025-02-03 12:35:24 +10:00
|
|
|
static void
|
2018-09-08 18:08:48 +08:00
|
|
|
js_free_sftbl_entry(void *priv, JSHashEntry *he, uintN flag)
|
|
|
|
|
{
|
|
|
|
|
if (flag != HT_FREE_ENTRY)
|
|
|
|
|
return;
|
2025-02-05 12:40:54 +10:00
|
|
|
js_free(he);
|
2018-09-08 18:08:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static JSHashAllocOps sftbl_alloc_ops = {
|
|
|
|
|
js_alloc_table_space, js_free_table_space,
|
|
|
|
|
js_alloc_sftbl_entry, js_free_sftbl_entry
|
|
|
|
|
};
|
|
|
|
|
|
2025-02-05 12:40:54 +10:00
|
|
|
static void
|
|
|
|
|
FinishRuntimeScriptState(JSRuntime *rt)
|
|
|
|
|
{
|
|
|
|
|
if (rt->scriptFilenameTable) {
|
|
|
|
|
JS_HashTableDestroy(rt->scriptFilenameTable);
|
|
|
|
|
rt->scriptFilenameTable = NULL;
|
|
|
|
|
}
|
|
|
|
|
#ifdef JS_THREADSAFE
|
|
|
|
|
if (rt->scriptFilenameTableLock) {
|
|
|
|
|
JS_DESTROY_LOCK(rt->scriptFilenameTableLock);
|
|
|
|
|
rt->scriptFilenameTableLock = NULL;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-08 18:08:48 +08:00
|
|
|
JSBool
|
|
|
|
|
js_InitRuntimeScriptState(JSRuntime *rt)
|
|
|
|
|
{
|
|
|
|
|
#ifdef JS_THREADSAFE
|
|
|
|
|
JS_ASSERT(!rt->scriptFilenameTableLock);
|
|
|
|
|
rt->scriptFilenameTableLock = JS_NEW_LOCK();
|
|
|
|
|
if (!rt->scriptFilenameTableLock)
|
|
|
|
|
return JS_FALSE;
|
|
|
|
|
#endif
|
|
|
|
|
JS_ASSERT(!rt->scriptFilenameTable);
|
|
|
|
|
rt->scriptFilenameTable =
|
|
|
|
|
JS_NewHashTable(16, JS_HashString, js_compare_strings, NULL,
|
|
|
|
|
&sftbl_alloc_ops, NULL);
|
|
|
|
|
if (!rt->scriptFilenameTable) {
|
2025-02-05 12:40:54 +10:00
|
|
|
FinishRuntimeScriptState(rt); /* free lock if threadsafe */
|
2018-09-08 18:08:48 +08:00
|
|
|
return JS_FALSE;
|
|
|
|
|
}
|
|
|
|
|
JS_INIT_CLIST(&rt->scriptFilenamePrefixes);
|
|
|
|
|
return JS_TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
typedef struct ScriptFilenamePrefix {
|
|
|
|
|
JSCList links; /* circular list linkage for easy deletion */
|
|
|
|
|
const char *name; /* pointer to pinned ScriptFilenameEntry string */
|
|
|
|
|
size_t length; /* prefix string length, precomputed */
|
|
|
|
|
uint32 flags; /* user-defined flags to inherit from this prefix */
|
|
|
|
|
} ScriptFilenamePrefix;
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
js_FreeRuntimeScriptState(JSRuntime *rt)
|
|
|
|
|
{
|
Numerous changes with focus on feature and stability parity across Windows, Linux and MacOS platforms
Added new Makefile that handles compiling UOX3 and Spidermonkey on both Linux and MacOS (punt)
Added VS solution (SpiderMonkey.sln) and VC++ project files for compiling SpiderMonkey on Windows (Xuri)
Updated SpiderMonkey from v1.6.0 to v1.7.0
Added optimization flag -O2 for release build in CMakeLists.txt in project root (Xuri)
Added StringUtility file with general common string manipulation functions (punt)
Updated RandomNum function to use a "seedless" random number generator from C++11 instead of the old C rand() function. (punt)
Overall code cleanup to remove/replace platform-dependent code (punt)
Replaced potentially unsafe usage of C string stuff like sprintf, vsprintf, vsnprintf, strncat, strcpy and strlen throughout the code with calls to a format() function containing only a single, safe use of vsnprintf, ensuring there's a single place of failure if there's anything to fix and and making it easy to potentially replace this with std::format from C++20 when the time comes. (punt)
Replaced usage of char in many places with std::string (punt)
Started process of replacing UString usage with functions provided through StringUtility instead (punt)
Replaced platform specific fileIO handling in Windows/Linux with cross-platform C++17 standard std::filesystem (punt)
Replaced platform specific time handling by using cross-platform chrono library (punt)
Removed UOX namespace to reduce complexity (punt)
Elimitated template code approach to singletons for more modern c++ constructs, removing dependices in the process (punt)
Removed ODBC support; it hasn't been touched since the initial implementation in 2008, and there is a lack of someone to maintain the code. (punt)
Removed some platform specific files like uoxlinux.h, which is no longer required (punt)
Removed legacy crash protection code, and removed support for cluox (punt)
Removed legacy "support" for Borland compiler (punt)
Removed legacy VC++ 6 Workspace/Project files, VS2005 Solution/Project files, as these are no longer supported (Xuri)
Removed legacy BUILD folder with outdated compilation instructions (Xuri)
Removed old Changelog file (merged into Changelog.txt) (Xuri)
Fixed a pointer bug for items in multis on world load (punt)
Fixed a dictionary related issue that caused segmentation faults on Linux/MacOS (punt)
Fixed an issue with callbacks to JS scripts that caused segmentation faults on Linux/MacOS (punt)
Paths in uox.ini should now load properly on all platforms regardless of whether those paths use slashes or backslashes, and whether or not they end in a slash/backslash. (punt)
Moved to c++17 style of threading, and got rid of threadsafeobject.cpp/h (punt)
Replaced parsing of UOX.INI tags with a system that's more easily maintainable (punt)
Added some new commands to js/commands/custom/misc-cmd.js (Xuri)
cont // Targeted item will be made a container, set to nondecay and movable 2
endfight // Targeted character (and character being fought) will stop fighting
getmulti // Get multiObject for targeted item
finditem // Find item at layer X
movespeed // Set movement speed of target player (0x0 Normal, 0x1 Mounted, 0x2 Slow (walk only), 0x3 Hybrid ("jog"?), 0x4 Frozen)
Added new HTML based documentation in docs folder, and removed many old legacy docs that are either incorporated into this document already or no longer relevant for the current UOX3 version (Xuri)
Co-Authored-By: Charles Kerr <punt1959@users.noreply.github.com>
2020-09-07 18:09:55 +08:00
|
|
|
if (!rt->scriptFilenameTable)
|
|
|
|
|
return;
|
|
|
|
|
|
2018-09-08 18:08:48 +08:00
|
|
|
while (!JS_CLIST_IS_EMPTY(&rt->scriptFilenamePrefixes)) {
|
2025-02-05 12:40:54 +10:00
|
|
|
ScriptFilenamePrefix *sfp = (ScriptFilenamePrefix *)
|
|
|
|
|
rt->scriptFilenamePrefixes.next;
|
2018-09-08 18:08:48 +08:00
|
|
|
JS_REMOVE_LINK(&sfp->links);
|
2025-02-05 12:40:54 +10:00
|
|
|
js_free(sfp);
|
2018-09-08 18:08:48 +08:00
|
|
|
}
|
2025-02-05 12:40:54 +10:00
|
|
|
FinishRuntimeScriptState(rt);
|
2018-09-08 18:08:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#ifdef DEBUG_brendan
|
Numerous changes with focus on feature and stability parity across Windows, Linux and MacOS platforms
Added new Makefile that handles compiling UOX3 and Spidermonkey on both Linux and MacOS (punt)
Added VS solution (SpiderMonkey.sln) and VC++ project files for compiling SpiderMonkey on Windows (Xuri)
Updated SpiderMonkey from v1.6.0 to v1.7.0
Added optimization flag -O2 for release build in CMakeLists.txt in project root (Xuri)
Added StringUtility file with general common string manipulation functions (punt)
Updated RandomNum function to use a "seedless" random number generator from C++11 instead of the old C rand() function. (punt)
Overall code cleanup to remove/replace platform-dependent code (punt)
Replaced potentially unsafe usage of C string stuff like sprintf, vsprintf, vsnprintf, strncat, strcpy and strlen throughout the code with calls to a format() function containing only a single, safe use of vsnprintf, ensuring there's a single place of failure if there's anything to fix and and making it easy to potentially replace this with std::format from C++20 when the time comes. (punt)
Replaced usage of char in many places with std::string (punt)
Started process of replacing UString usage with functions provided through StringUtility instead (punt)
Replaced platform specific fileIO handling in Windows/Linux with cross-platform C++17 standard std::filesystem (punt)
Replaced platform specific time handling by using cross-platform chrono library (punt)
Removed UOX namespace to reduce complexity (punt)
Elimitated template code approach to singletons for more modern c++ constructs, removing dependices in the process (punt)
Removed ODBC support; it hasn't been touched since the initial implementation in 2008, and there is a lack of someone to maintain the code. (punt)
Removed some platform specific files like uoxlinux.h, which is no longer required (punt)
Removed legacy crash protection code, and removed support for cluox (punt)
Removed legacy "support" for Borland compiler (punt)
Removed legacy VC++ 6 Workspace/Project files, VS2005 Solution/Project files, as these are no longer supported (Xuri)
Removed legacy BUILD folder with outdated compilation instructions (Xuri)
Removed old Changelog file (merged into Changelog.txt) (Xuri)
Fixed a pointer bug for items in multis on world load (punt)
Fixed a dictionary related issue that caused segmentation faults on Linux/MacOS (punt)
Fixed an issue with callbacks to JS scripts that caused segmentation faults on Linux/MacOS (punt)
Paths in uox.ini should now load properly on all platforms regardless of whether those paths use slashes or backslashes, and whether or not they end in a slash/backslash. (punt)
Moved to c++17 style of threading, and got rid of threadsafeobject.cpp/h (punt)
Replaced parsing of UOX.INI tags with a system that's more easily maintainable (punt)
Added some new commands to js/commands/custom/misc-cmd.js (Xuri)
cont // Targeted item will be made a container, set to nondecay and movable 2
endfight // Targeted character (and character being fought) will stop fighting
getmulti // Get multiObject for targeted item
finditem // Find item at layer X
movespeed // Set movement speed of target player (0x0 Normal, 0x1 Mounted, 0x2 Slow (walk only), 0x3 Hybrid ("jog"?), 0x4 Frozen)
Added new HTML based documentation in docs folder, and removed many old legacy docs that are either incorporated into this document already or no longer relevant for the current UOX3 version (Xuri)
Co-Authored-By: Charles Kerr <punt1959@users.noreply.github.com>
2020-09-07 18:09:55 +08:00
|
|
|
#define DEBUG_SFTBL
|
|
|
|
|
#endif
|
|
|
|
|
#ifdef DEBUG_SFTBL
|
2018-09-08 18:08:48 +08:00
|
|
|
size_t sftbl_savings = 0;
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
static ScriptFilenameEntry *
|
|
|
|
|
SaveScriptFilename(JSRuntime *rt, const char *filename, uint32 flags)
|
|
|
|
|
{
|
|
|
|
|
JSHashTable *table;
|
|
|
|
|
JSHashNumber hash;
|
|
|
|
|
JSHashEntry **hep;
|
|
|
|
|
ScriptFilenameEntry *sfe;
|
|
|
|
|
size_t length;
|
|
|
|
|
JSCList *head, *link;
|
|
|
|
|
ScriptFilenamePrefix *sfp;
|
|
|
|
|
|
|
|
|
|
table = rt->scriptFilenameTable;
|
|
|
|
|
hash = JS_HashString(filename);
|
|
|
|
|
hep = JS_HashTableRawLookup(table, hash, filename);
|
|
|
|
|
sfe = (ScriptFilenameEntry *) *hep;
|
Numerous changes with focus on feature and stability parity across Windows, Linux and MacOS platforms
Added new Makefile that handles compiling UOX3 and Spidermonkey on both Linux and MacOS (punt)
Added VS solution (SpiderMonkey.sln) and VC++ project files for compiling SpiderMonkey on Windows (Xuri)
Updated SpiderMonkey from v1.6.0 to v1.7.0
Added optimization flag -O2 for release build in CMakeLists.txt in project root (Xuri)
Added StringUtility file with general common string manipulation functions (punt)
Updated RandomNum function to use a "seedless" random number generator from C++11 instead of the old C rand() function. (punt)
Overall code cleanup to remove/replace platform-dependent code (punt)
Replaced potentially unsafe usage of C string stuff like sprintf, vsprintf, vsnprintf, strncat, strcpy and strlen throughout the code with calls to a format() function containing only a single, safe use of vsnprintf, ensuring there's a single place of failure if there's anything to fix and and making it easy to potentially replace this with std::format from C++20 when the time comes. (punt)
Replaced usage of char in many places with std::string (punt)
Started process of replacing UString usage with functions provided through StringUtility instead (punt)
Replaced platform specific fileIO handling in Windows/Linux with cross-platform C++17 standard std::filesystem (punt)
Replaced platform specific time handling by using cross-platform chrono library (punt)
Removed UOX namespace to reduce complexity (punt)
Elimitated template code approach to singletons for more modern c++ constructs, removing dependices in the process (punt)
Removed ODBC support; it hasn't been touched since the initial implementation in 2008, and there is a lack of someone to maintain the code. (punt)
Removed some platform specific files like uoxlinux.h, which is no longer required (punt)
Removed legacy crash protection code, and removed support for cluox (punt)
Removed legacy "support" for Borland compiler (punt)
Removed legacy VC++ 6 Workspace/Project files, VS2005 Solution/Project files, as these are no longer supported (Xuri)
Removed legacy BUILD folder with outdated compilation instructions (Xuri)
Removed old Changelog file (merged into Changelog.txt) (Xuri)
Fixed a pointer bug for items in multis on world load (punt)
Fixed a dictionary related issue that caused segmentation faults on Linux/MacOS (punt)
Fixed an issue with callbacks to JS scripts that caused segmentation faults on Linux/MacOS (punt)
Paths in uox.ini should now load properly on all platforms regardless of whether those paths use slashes or backslashes, and whether or not they end in a slash/backslash. (punt)
Moved to c++17 style of threading, and got rid of threadsafeobject.cpp/h (punt)
Replaced parsing of UOX.INI tags with a system that's more easily maintainable (punt)
Added some new commands to js/commands/custom/misc-cmd.js (Xuri)
cont // Targeted item will be made a container, set to nondecay and movable 2
endfight // Targeted character (and character being fought) will stop fighting
getmulti // Get multiObject for targeted item
finditem // Find item at layer X
movespeed // Set movement speed of target player (0x0 Normal, 0x1 Mounted, 0x2 Slow (walk only), 0x3 Hybrid ("jog"?), 0x4 Frozen)
Added new HTML based documentation in docs folder, and removed many old legacy docs that are either incorporated into this document already or no longer relevant for the current UOX3 version (Xuri)
Co-Authored-By: Charles Kerr <punt1959@users.noreply.github.com>
2020-09-07 18:09:55 +08:00
|
|
|
#ifdef DEBUG_SFTBL
|
2018-09-08 18:08:48 +08:00
|
|
|
if (sfe)
|
|
|
|
|
sftbl_savings += strlen(sfe->filename);
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
if (!sfe) {
|
|
|
|
|
sfe = (ScriptFilenameEntry *)
|
|
|
|
|
JS_HashTableRawAdd(table, hep, hash, filename, NULL);
|
|
|
|
|
if (!sfe)
|
|
|
|
|
return NULL;
|
|
|
|
|
sfe->key = strcpy(sfe->filename, filename);
|
|
|
|
|
sfe->flags = 0;
|
|
|
|
|
sfe->mark = JS_FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* If saving a prefix, add it to the set in rt->scriptFilenamePrefixes. */
|
|
|
|
|
if (flags != 0) {
|
|
|
|
|
/* Search in case filename was saved already; we must be idempotent. */
|
|
|
|
|
sfp = NULL;
|
|
|
|
|
length = strlen(filename);
|
|
|
|
|
for (head = link = &rt->scriptFilenamePrefixes;
|
|
|
|
|
link->next != head;
|
|
|
|
|
link = link->next) {
|
|
|
|
|
/* Lag link behind sfp to insert in non-increasing length order. */
|
|
|
|
|
sfp = (ScriptFilenamePrefix *) link->next;
|
|
|
|
|
if (!strcmp(sfp->name, filename))
|
|
|
|
|
break;
|
|
|
|
|
if (sfp->length <= length) {
|
|
|
|
|
sfp = NULL;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
sfp = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!sfp) {
|
|
|
|
|
/* No such prefix: add one now. */
|
2025-02-05 12:40:54 +10:00
|
|
|
sfp = (ScriptFilenamePrefix *) js_malloc(sizeof(ScriptFilenamePrefix));
|
2018-09-08 18:08:48 +08:00
|
|
|
if (!sfp)
|
|
|
|
|
return NULL;
|
|
|
|
|
JS_INSERT_AFTER(&sfp->links, link);
|
|
|
|
|
sfp->name = sfe->filename;
|
|
|
|
|
sfp->length = length;
|
|
|
|
|
sfp->flags = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Accumulate flags in both sfe and sfp: sfe for later access from the
|
|
|
|
|
* JS_GetScriptedCallerFilenameFlags debug-API, and sfp so that longer
|
|
|
|
|
* filename entries can inherit by prefix.
|
|
|
|
|
*/
|
|
|
|
|
sfe->flags |= flags;
|
|
|
|
|
sfp->flags |= flags;
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-19 21:25:58 +10:00
|
|
|
#ifdef DEBUG
|
|
|
|
|
if (rt->functionMeterFilename) {
|
|
|
|
|
size_t len = strlen(sfe->filename);
|
|
|
|
|
if (len >= sizeof rt->lastScriptFilename)
|
|
|
|
|
len = sizeof rt->lastScriptFilename - 1;
|
|
|
|
|
memcpy(rt->lastScriptFilename, sfe->filename, len);
|
|
|
|
|
rt->lastScriptFilename[len] = '\0';
|
|
|
|
|
}
|
2025-02-05 12:40:54 +10:00
|
|
|
#endif
|
|
|
|
|
|
2018-09-08 18:08:48 +08:00
|
|
|
return sfe;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const char *
|
|
|
|
|
js_SaveScriptFilename(JSContext *cx, const char *filename)
|
|
|
|
|
{
|
|
|
|
|
JSRuntime *rt;
|
|
|
|
|
ScriptFilenameEntry *sfe;
|
|
|
|
|
JSCList *head, *link;
|
|
|
|
|
ScriptFilenamePrefix *sfp;
|
|
|
|
|
|
|
|
|
|
rt = cx->runtime;
|
|
|
|
|
JS_ACQUIRE_LOCK(rt->scriptFilenameTableLock);
|
|
|
|
|
sfe = SaveScriptFilename(rt, filename, 0);
|
|
|
|
|
if (!sfe) {
|
|
|
|
|
JS_RELEASE_LOCK(rt->scriptFilenameTableLock);
|
|
|
|
|
JS_ReportOutOfMemory(cx);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Try to inherit flags by prefix. We assume there won't be more than a
|
|
|
|
|
* few (dozen! ;-) prefixes, so linear search is tolerable.
|
|
|
|
|
* XXXbe every time I've assumed that in the JS engine, I've been wrong!
|
|
|
|
|
*/
|
|
|
|
|
for (head = &rt->scriptFilenamePrefixes, link = head->next;
|
|
|
|
|
link != head;
|
|
|
|
|
link = link->next) {
|
|
|
|
|
sfp = (ScriptFilenamePrefix *) link;
|
|
|
|
|
if (!strncmp(sfp->name, filename, sfp->length)) {
|
|
|
|
|
sfe->flags |= sfp->flags;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
JS_RELEASE_LOCK(rt->scriptFilenameTableLock);
|
|
|
|
|
return sfe->filename;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const char *
|
|
|
|
|
js_SaveScriptFilenameRT(JSRuntime *rt, const char *filename, uint32 flags)
|
|
|
|
|
{
|
|
|
|
|
ScriptFilenameEntry *sfe;
|
|
|
|
|
|
|
|
|
|
/* This may be called very early, via the jsdbgapi.h entry point. */
|
|
|
|
|
if (!rt->scriptFilenameTable && !js_InitRuntimeScriptState(rt))
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
JS_ACQUIRE_LOCK(rt->scriptFilenameTableLock);
|
|
|
|
|
sfe = SaveScriptFilename(rt, filename, flags);
|
|
|
|
|
JS_RELEASE_LOCK(rt->scriptFilenameTableLock);
|
|
|
|
|
if (!sfe)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
return sfe->filename;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Back up from a saved filename by its offset within its hash table entry.
|
|
|
|
|
*/
|
|
|
|
|
#define FILENAME_TO_SFE(fn) \
|
|
|
|
|
((ScriptFilenameEntry *) ((fn) - offsetof(ScriptFilenameEntry, filename)))
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* The sfe->key member, redundant given sfe->filename but required by the old
|
|
|
|
|
* jshash.c code, here gives us a useful sanity check. This assertion will
|
|
|
|
|
* very likely botch if someone tries to mark a string that wasn't allocated
|
|
|
|
|
* as an sfe->filename.
|
|
|
|
|
*/
|
|
|
|
|
#define ASSERT_VALID_SFE(sfe) JS_ASSERT((sfe)->key == (sfe)->filename)
|
|
|
|
|
|
|
|
|
|
uint32
|
|
|
|
|
js_GetScriptFilenameFlags(const char *filename)
|
|
|
|
|
{
|
|
|
|
|
ScriptFilenameEntry *sfe;
|
|
|
|
|
|
|
|
|
|
sfe = FILENAME_TO_SFE(filename);
|
|
|
|
|
ASSERT_VALID_SFE(sfe);
|
|
|
|
|
return sfe->flags;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
js_MarkScriptFilename(const char *filename)
|
|
|
|
|
{
|
|
|
|
|
ScriptFilenameEntry *sfe;
|
|
|
|
|
|
|
|
|
|
sfe = FILENAME_TO_SFE(filename);
|
|
|
|
|
ASSERT_VALID_SFE(sfe);
|
|
|
|
|
sfe->mark = JS_TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-03 12:35:24 +10:00
|
|
|
static intN
|
2018-09-08 18:08:48 +08:00
|
|
|
js_script_filename_marker(JSHashEntry *he, intN i, void *arg)
|
|
|
|
|
{
|
|
|
|
|
ScriptFilenameEntry *sfe = (ScriptFilenameEntry *) he;
|
|
|
|
|
|
|
|
|
|
sfe->mark = JS_TRUE;
|
|
|
|
|
return HT_ENUMERATE_NEXT;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2025-02-05 12:40:54 +10:00
|
|
|
js_MarkScriptFilenames(JSRuntime *rt)
|
2018-09-08 18:08:48 +08:00
|
|
|
{
|
|
|
|
|
JSCList *head, *link;
|
|
|
|
|
ScriptFilenamePrefix *sfp;
|
|
|
|
|
|
Numerous changes with focus on feature and stability parity across Windows, Linux and MacOS platforms
Added new Makefile that handles compiling UOX3 and Spidermonkey on both Linux and MacOS (punt)
Added VS solution (SpiderMonkey.sln) and VC++ project files for compiling SpiderMonkey on Windows (Xuri)
Updated SpiderMonkey from v1.6.0 to v1.7.0
Added optimization flag -O2 for release build in CMakeLists.txt in project root (Xuri)
Added StringUtility file with general common string manipulation functions (punt)
Updated RandomNum function to use a "seedless" random number generator from C++11 instead of the old C rand() function. (punt)
Overall code cleanup to remove/replace platform-dependent code (punt)
Replaced potentially unsafe usage of C string stuff like sprintf, vsprintf, vsnprintf, strncat, strcpy and strlen throughout the code with calls to a format() function containing only a single, safe use of vsnprintf, ensuring there's a single place of failure if there's anything to fix and and making it easy to potentially replace this with std::format from C++20 when the time comes. (punt)
Replaced usage of char in many places with std::string (punt)
Started process of replacing UString usage with functions provided through StringUtility instead (punt)
Replaced platform specific fileIO handling in Windows/Linux with cross-platform C++17 standard std::filesystem (punt)
Replaced platform specific time handling by using cross-platform chrono library (punt)
Removed UOX namespace to reduce complexity (punt)
Elimitated template code approach to singletons for more modern c++ constructs, removing dependices in the process (punt)
Removed ODBC support; it hasn't been touched since the initial implementation in 2008, and there is a lack of someone to maintain the code. (punt)
Removed some platform specific files like uoxlinux.h, which is no longer required (punt)
Removed legacy crash protection code, and removed support for cluox (punt)
Removed legacy "support" for Borland compiler (punt)
Removed legacy VC++ 6 Workspace/Project files, VS2005 Solution/Project files, as these are no longer supported (Xuri)
Removed legacy BUILD folder with outdated compilation instructions (Xuri)
Removed old Changelog file (merged into Changelog.txt) (Xuri)
Fixed a pointer bug for items in multis on world load (punt)
Fixed a dictionary related issue that caused segmentation faults on Linux/MacOS (punt)
Fixed an issue with callbacks to JS scripts that caused segmentation faults on Linux/MacOS (punt)
Paths in uox.ini should now load properly on all platforms regardless of whether those paths use slashes or backslashes, and whether or not they end in a slash/backslash. (punt)
Moved to c++17 style of threading, and got rid of threadsafeobject.cpp/h (punt)
Replaced parsing of UOX.INI tags with a system that's more easily maintainable (punt)
Added some new commands to js/commands/custom/misc-cmd.js (Xuri)
cont // Targeted item will be made a container, set to nondecay and movable 2
endfight // Targeted character (and character being fought) will stop fighting
getmulti // Get multiObject for targeted item
finditem // Find item at layer X
movespeed // Set movement speed of target player (0x0 Normal, 0x1 Mounted, 0x2 Slow (walk only), 0x3 Hybrid ("jog"?), 0x4 Frozen)
Added new HTML based documentation in docs folder, and removed many old legacy docs that are either incorporated into this document already or no longer relevant for the current UOX3 version (Xuri)
Co-Authored-By: Charles Kerr <punt1959@users.noreply.github.com>
2020-09-07 18:09:55 +08:00
|
|
|
if (!rt->scriptFilenameTable)
|
|
|
|
|
return;
|
|
|
|
|
|
2025-02-05 12:40:54 +10:00
|
|
|
if (rt->gcKeepAtoms) {
|
2018-09-08 18:08:48 +08:00
|
|
|
JS_HashTableEnumerateEntries(rt->scriptFilenameTable,
|
|
|
|
|
js_script_filename_marker,
|
|
|
|
|
rt);
|
|
|
|
|
}
|
|
|
|
|
for (head = &rt->scriptFilenamePrefixes, link = head->next;
|
|
|
|
|
link != head;
|
|
|
|
|
link = link->next) {
|
|
|
|
|
sfp = (ScriptFilenamePrefix *) link;
|
|
|
|
|
js_MarkScriptFilename(sfp->name);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-03 12:35:24 +10:00
|
|
|
static intN
|
2018-09-08 18:08:48 +08:00
|
|
|
js_script_filename_sweeper(JSHashEntry *he, intN i, void *arg)
|
|
|
|
|
{
|
|
|
|
|
ScriptFilenameEntry *sfe = (ScriptFilenameEntry *) he;
|
|
|
|
|
|
|
|
|
|
if (!sfe->mark)
|
|
|
|
|
return HT_ENUMERATE_REMOVE;
|
|
|
|
|
sfe->mark = JS_FALSE;
|
|
|
|
|
return HT_ENUMERATE_NEXT;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
js_SweepScriptFilenames(JSRuntime *rt)
|
|
|
|
|
{
|
Numerous changes with focus on feature and stability parity across Windows, Linux and MacOS platforms
Added new Makefile that handles compiling UOX3 and Spidermonkey on both Linux and MacOS (punt)
Added VS solution (SpiderMonkey.sln) and VC++ project files for compiling SpiderMonkey on Windows (Xuri)
Updated SpiderMonkey from v1.6.0 to v1.7.0
Added optimization flag -O2 for release build in CMakeLists.txt in project root (Xuri)
Added StringUtility file with general common string manipulation functions (punt)
Updated RandomNum function to use a "seedless" random number generator from C++11 instead of the old C rand() function. (punt)
Overall code cleanup to remove/replace platform-dependent code (punt)
Replaced potentially unsafe usage of C string stuff like sprintf, vsprintf, vsnprintf, strncat, strcpy and strlen throughout the code with calls to a format() function containing only a single, safe use of vsnprintf, ensuring there's a single place of failure if there's anything to fix and and making it easy to potentially replace this with std::format from C++20 when the time comes. (punt)
Replaced usage of char in many places with std::string (punt)
Started process of replacing UString usage with functions provided through StringUtility instead (punt)
Replaced platform specific fileIO handling in Windows/Linux with cross-platform C++17 standard std::filesystem (punt)
Replaced platform specific time handling by using cross-platform chrono library (punt)
Removed UOX namespace to reduce complexity (punt)
Elimitated template code approach to singletons for more modern c++ constructs, removing dependices in the process (punt)
Removed ODBC support; it hasn't been touched since the initial implementation in 2008, and there is a lack of someone to maintain the code. (punt)
Removed some platform specific files like uoxlinux.h, which is no longer required (punt)
Removed legacy crash protection code, and removed support for cluox (punt)
Removed legacy "support" for Borland compiler (punt)
Removed legacy VC++ 6 Workspace/Project files, VS2005 Solution/Project files, as these are no longer supported (Xuri)
Removed legacy BUILD folder with outdated compilation instructions (Xuri)
Removed old Changelog file (merged into Changelog.txt) (Xuri)
Fixed a pointer bug for items in multis on world load (punt)
Fixed a dictionary related issue that caused segmentation faults on Linux/MacOS (punt)
Fixed an issue with callbacks to JS scripts that caused segmentation faults on Linux/MacOS (punt)
Paths in uox.ini should now load properly on all platforms regardless of whether those paths use slashes or backslashes, and whether or not they end in a slash/backslash. (punt)
Moved to c++17 style of threading, and got rid of threadsafeobject.cpp/h (punt)
Replaced parsing of UOX.INI tags with a system that's more easily maintainable (punt)
Added some new commands to js/commands/custom/misc-cmd.js (Xuri)
cont // Targeted item will be made a container, set to nondecay and movable 2
endfight // Targeted character (and character being fought) will stop fighting
getmulti // Get multiObject for targeted item
finditem // Find item at layer X
movespeed // Set movement speed of target player (0x0 Normal, 0x1 Mounted, 0x2 Slow (walk only), 0x3 Hybrid ("jog"?), 0x4 Frozen)
Added new HTML based documentation in docs folder, and removed many old legacy docs that are either incorporated into this document already or no longer relevant for the current UOX3 version (Xuri)
Co-Authored-By: Charles Kerr <punt1959@users.noreply.github.com>
2020-09-07 18:09:55 +08:00
|
|
|
if (!rt->scriptFilenameTable)
|
|
|
|
|
return;
|
|
|
|
|
|
2025-02-05 12:40:54 +10:00
|
|
|
/*
|
|
|
|
|
* JS_HashTableEnumerateEntries shrinks the table if many entries are
|
|
|
|
|
* removed preventing wasting memory on a too sparse table.
|
|
|
|
|
*/
|
2018-09-08 18:08:48 +08:00
|
|
|
JS_HashTableEnumerateEntries(rt->scriptFilenameTable,
|
|
|
|
|
js_script_filename_sweeper,
|
|
|
|
|
rt);
|
|
|
|
|
#ifdef DEBUG_notme
|
Numerous changes with focus on feature and stability parity across Windows, Linux and MacOS platforms
Added new Makefile that handles compiling UOX3 and Spidermonkey on both Linux and MacOS (punt)
Added VS solution (SpiderMonkey.sln) and VC++ project files for compiling SpiderMonkey on Windows (Xuri)
Updated SpiderMonkey from v1.6.0 to v1.7.0
Added optimization flag -O2 for release build in CMakeLists.txt in project root (Xuri)
Added StringUtility file with general common string manipulation functions (punt)
Updated RandomNum function to use a "seedless" random number generator from C++11 instead of the old C rand() function. (punt)
Overall code cleanup to remove/replace platform-dependent code (punt)
Replaced potentially unsafe usage of C string stuff like sprintf, vsprintf, vsnprintf, strncat, strcpy and strlen throughout the code with calls to a format() function containing only a single, safe use of vsnprintf, ensuring there's a single place of failure if there's anything to fix and and making it easy to potentially replace this with std::format from C++20 when the time comes. (punt)
Replaced usage of char in many places with std::string (punt)
Started process of replacing UString usage with functions provided through StringUtility instead (punt)
Replaced platform specific fileIO handling in Windows/Linux with cross-platform C++17 standard std::filesystem (punt)
Replaced platform specific time handling by using cross-platform chrono library (punt)
Removed UOX namespace to reduce complexity (punt)
Elimitated template code approach to singletons for more modern c++ constructs, removing dependices in the process (punt)
Removed ODBC support; it hasn't been touched since the initial implementation in 2008, and there is a lack of someone to maintain the code. (punt)
Removed some platform specific files like uoxlinux.h, which is no longer required (punt)
Removed legacy crash protection code, and removed support for cluox (punt)
Removed legacy "support" for Borland compiler (punt)
Removed legacy VC++ 6 Workspace/Project files, VS2005 Solution/Project files, as these are no longer supported (Xuri)
Removed legacy BUILD folder with outdated compilation instructions (Xuri)
Removed old Changelog file (merged into Changelog.txt) (Xuri)
Fixed a pointer bug for items in multis on world load (punt)
Fixed a dictionary related issue that caused segmentation faults on Linux/MacOS (punt)
Fixed an issue with callbacks to JS scripts that caused segmentation faults on Linux/MacOS (punt)
Paths in uox.ini should now load properly on all platforms regardless of whether those paths use slashes or backslashes, and whether or not they end in a slash/backslash. (punt)
Moved to c++17 style of threading, and got rid of threadsafeobject.cpp/h (punt)
Replaced parsing of UOX.INI tags with a system that's more easily maintainable (punt)
Added some new commands to js/commands/custom/misc-cmd.js (Xuri)
cont // Targeted item will be made a container, set to nondecay and movable 2
endfight // Targeted character (and character being fought) will stop fighting
getmulti // Get multiObject for targeted item
finditem // Find item at layer X
movespeed // Set movement speed of target player (0x0 Normal, 0x1 Mounted, 0x2 Slow (walk only), 0x3 Hybrid ("jog"?), 0x4 Frozen)
Added new HTML based documentation in docs folder, and removed many old legacy docs that are either incorporated into this document already or no longer relevant for the current UOX3 version (Xuri)
Co-Authored-By: Charles Kerr <punt1959@users.noreply.github.com>
2020-09-07 18:09:55 +08:00
|
|
|
#ifdef DEBUG_SFTBL
|
2018-09-08 18:08:48 +08:00
|
|
|
printf("script filename table savings so far: %u\n", sftbl_savings);
|
|
|
|
|
#endif
|
Numerous changes with focus on feature and stability parity across Windows, Linux and MacOS platforms
Added new Makefile that handles compiling UOX3 and Spidermonkey on both Linux and MacOS (punt)
Added VS solution (SpiderMonkey.sln) and VC++ project files for compiling SpiderMonkey on Windows (Xuri)
Updated SpiderMonkey from v1.6.0 to v1.7.0
Added optimization flag -O2 for release build in CMakeLists.txt in project root (Xuri)
Added StringUtility file with general common string manipulation functions (punt)
Updated RandomNum function to use a "seedless" random number generator from C++11 instead of the old C rand() function. (punt)
Overall code cleanup to remove/replace platform-dependent code (punt)
Replaced potentially unsafe usage of C string stuff like sprintf, vsprintf, vsnprintf, strncat, strcpy and strlen throughout the code with calls to a format() function containing only a single, safe use of vsnprintf, ensuring there's a single place of failure if there's anything to fix and and making it easy to potentially replace this with std::format from C++20 when the time comes. (punt)
Replaced usage of char in many places with std::string (punt)
Started process of replacing UString usage with functions provided through StringUtility instead (punt)
Replaced platform specific fileIO handling in Windows/Linux with cross-platform C++17 standard std::filesystem (punt)
Replaced platform specific time handling by using cross-platform chrono library (punt)
Removed UOX namespace to reduce complexity (punt)
Elimitated template code approach to singletons for more modern c++ constructs, removing dependices in the process (punt)
Removed ODBC support; it hasn't been touched since the initial implementation in 2008, and there is a lack of someone to maintain the code. (punt)
Removed some platform specific files like uoxlinux.h, which is no longer required (punt)
Removed legacy crash protection code, and removed support for cluox (punt)
Removed legacy "support" for Borland compiler (punt)
Removed legacy VC++ 6 Workspace/Project files, VS2005 Solution/Project files, as these are no longer supported (Xuri)
Removed legacy BUILD folder with outdated compilation instructions (Xuri)
Removed old Changelog file (merged into Changelog.txt) (Xuri)
Fixed a pointer bug for items in multis on world load (punt)
Fixed a dictionary related issue that caused segmentation faults on Linux/MacOS (punt)
Fixed an issue with callbacks to JS scripts that caused segmentation faults on Linux/MacOS (punt)
Paths in uox.ini should now load properly on all platforms regardless of whether those paths use slashes or backslashes, and whether or not they end in a slash/backslash. (punt)
Moved to c++17 style of threading, and got rid of threadsafeobject.cpp/h (punt)
Replaced parsing of UOX.INI tags with a system that's more easily maintainable (punt)
Added some new commands to js/commands/custom/misc-cmd.js (Xuri)
cont // Targeted item will be made a container, set to nondecay and movable 2
endfight // Targeted character (and character being fought) will stop fighting
getmulti // Get multiObject for targeted item
finditem // Find item at layer X
movespeed // Set movement speed of target player (0x0 Normal, 0x1 Mounted, 0x2 Slow (walk only), 0x3 Hybrid ("jog"?), 0x4 Frozen)
Added new HTML based documentation in docs folder, and removed many old legacy docs that are either incorporated into this document already or no longer relevant for the current UOX3 version (Xuri)
Co-Authored-By: Charles Kerr <punt1959@users.noreply.github.com>
2020-09-07 18:09:55 +08:00
|
|
|
#endif
|
2018-09-08 18:08:48 +08:00
|
|
|
}
|
|
|
|
|
|
2023-07-12 13:27:26 +10:00
|
|
|
/*
|
|
|
|
|
* JSScript data structures memory alignment:
|
|
|
|
|
*
|
|
|
|
|
* JSScript
|
|
|
|
|
* JSObjectArray script objects' descriptor if JSScript.objectsOffset != 0,
|
2025-02-05 12:40:54 +10:00
|
|
|
* use script->objects() to access it.
|
2023-07-12 13:27:26 +10:00
|
|
|
* JSObjectArray script regexps' descriptor if JSScript.regexpsOffset != 0,
|
2025-02-05 12:40:54 +10:00
|
|
|
* use script->regexps() to access it.
|
2023-07-12 13:27:26 +10:00
|
|
|
* JSTryNoteArray script try notes' descriptor if JSScript.tryNotesOffset
|
2025-02-05 12:40:54 +10:00
|
|
|
* != 0, use script->trynotes() to access it.
|
2023-07-12 13:27:26 +10:00
|
|
|
* JSAtom *a[] array of JSScript.atomMap.length atoms pointed by
|
|
|
|
|
* JSScript.atomMap.vector if any.
|
2025-02-05 12:40:54 +10:00
|
|
|
* JSObject *o[] array of script->objects()->length objects if any
|
|
|
|
|
* pointed by script->objects()->vector.
|
|
|
|
|
* JSObject *r[] array of script->regexps()->length regexps if any
|
|
|
|
|
* pointed by script->regexps()->vector.
|
|
|
|
|
* JSTryNote t[] array of script->trynotes()->length try notes if any
|
|
|
|
|
* pointed by script->trynotes()->vector.
|
2023-07-12 13:27:26 +10:00
|
|
|
* jsbytecode b[] script bytecode pointed by JSScript.code.
|
2025-02-05 12:40:54 +10:00
|
|
|
* jssrcnote s[] script source notes, use script->notes() to access it
|
2023-07-12 13:27:26 +10:00
|
|
|
*
|
|
|
|
|
* The alignment avoids gaps between entries as alignment requirement for each
|
|
|
|
|
* subsequent structure or array is the same or divides the alignment
|
|
|
|
|
* requirement for the previous one.
|
|
|
|
|
*
|
|
|
|
|
* The followings asserts checks that assuming that the alignment requirement
|
|
|
|
|
* for JSObjectArray and JSTryNoteArray are sizeof(void *) and for JSTryNote
|
|
|
|
|
* it is sizeof(uint32) as the structure consists of 3 uint32 fields.
|
|
|
|
|
*/
|
|
|
|
|
JS_STATIC_ASSERT(sizeof(JSScript) % sizeof(void *) == 0);
|
|
|
|
|
JS_STATIC_ASSERT(sizeof(JSObjectArray) % sizeof(void *) == 0);
|
|
|
|
|
JS_STATIC_ASSERT(sizeof(JSTryNoteArray) == sizeof(JSObjectArray));
|
|
|
|
|
JS_STATIC_ASSERT(sizeof(JSAtom *) == sizeof(JSObject *));
|
|
|
|
|
JS_STATIC_ASSERT(sizeof(JSObject *) % sizeof(uint32) == 0);
|
|
|
|
|
JS_STATIC_ASSERT(sizeof(JSTryNote) == 3 * sizeof(uint32));
|
|
|
|
|
JS_STATIC_ASSERT(sizeof(uint32) % sizeof(jsbytecode) == 0);
|
|
|
|
|
JS_STATIC_ASSERT(sizeof(jsbytecode) % sizeof(jssrcnote) == 0);
|
|
|
|
|
|
|
|
|
|
/*
|
2025-03-19 21:25:58 +10:00
|
|
|
* Check that uint8 offsets is enough to reach any optional array allocated
|
|
|
|
|
* after JSScript. For that we check that the maximum possible offset for
|
|
|
|
|
* JSConstArray, that last optional array, still fits 1 byte and do not
|
|
|
|
|
* coincide with INVALID_OFFSET.
|
2023-07-12 13:27:26 +10:00
|
|
|
*/
|
2025-03-19 21:25:58 +10:00
|
|
|
JS_STATIC_ASSERT(sizeof(JSObjectArray) +
|
|
|
|
|
sizeof(JSUpvarArray) +
|
|
|
|
|
sizeof(JSObjectArray) +
|
|
|
|
|
sizeof(JSTryNoteArray) +
|
|
|
|
|
sizeof(js::GlobalSlotArray)
|
|
|
|
|
< JSScript::INVALID_OFFSET);
|
|
|
|
|
JS_STATIC_ASSERT(JSScript::INVALID_OFFSET <= 255);
|
2023-07-12 13:27:26 +10:00
|
|
|
|
2018-09-08 18:08:48 +08:00
|
|
|
JSScript *
|
2025-03-19 21:25:58 +10:00
|
|
|
JSScript::NewScript(JSContext *cx, uint32 length, uint32 nsrcnotes, uint32 natoms,
|
|
|
|
|
uint32 nobjects, uint32 nupvars, uint32 nregexps,
|
|
|
|
|
uint32 ntrynotes, uint32 nconsts, uint32 nglobals,
|
|
|
|
|
uint16 nClosedArgs, uint16 nClosedVars, JSVersion version)
|
2018-09-08 18:08:48 +08:00
|
|
|
{
|
2023-07-12 13:27:26 +10:00
|
|
|
size_t size, vectorSize;
|
2018-09-08 18:08:48 +08:00
|
|
|
JSScript *script;
|
2023-07-12 13:27:26 +10:00
|
|
|
uint8 *cursor;
|
2025-03-19 21:25:58 +10:00
|
|
|
unsigned constPadding = 0;
|
|
|
|
|
|
|
|
|
|
uint32 totalClosed = nClosedArgs + nClosedVars;
|
2023-07-12 13:27:26 +10:00
|
|
|
|
|
|
|
|
size = sizeof(JSScript) +
|
2025-03-19 21:25:58 +10:00
|
|
|
sizeof(JSAtom *) * natoms;
|
|
|
|
|
|
2023-07-12 13:27:26 +10:00
|
|
|
if (nobjects != 0)
|
|
|
|
|
size += sizeof(JSObjectArray) + nobjects * sizeof(JSObject *);
|
2025-02-03 12:35:24 +10:00
|
|
|
if (nupvars != 0)
|
|
|
|
|
size += sizeof(JSUpvarArray) + nupvars * sizeof(uint32);
|
2023-07-12 13:27:26 +10:00
|
|
|
if (nregexps != 0)
|
|
|
|
|
size += sizeof(JSObjectArray) + nregexps * sizeof(JSObject *);
|
|
|
|
|
if (ntrynotes != 0)
|
|
|
|
|
size += sizeof(JSTryNoteArray) + ntrynotes * sizeof(JSTryNote);
|
2025-03-19 21:25:58 +10:00
|
|
|
if (nglobals != 0)
|
|
|
|
|
size += sizeof(GlobalSlotArray) + nglobals * sizeof(GlobalSlotArray::Entry);
|
|
|
|
|
if (totalClosed != 0)
|
|
|
|
|
size += totalClosed * sizeof(uint32);
|
|
|
|
|
|
|
|
|
|
if (nconsts != 0) {
|
|
|
|
|
size += sizeof(JSConstArray);
|
|
|
|
|
/*
|
|
|
|
|
* Calculate padding assuming that consts go after the other arrays,
|
|
|
|
|
* but before the bytecode and source notes.
|
|
|
|
|
*/
|
|
|
|
|
constPadding = (8 - (size % 8)) % 8;
|
|
|
|
|
size += constPadding + nconsts * sizeof(Value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
size += length * sizeof(jsbytecode) +
|
|
|
|
|
nsrcnotes * sizeof(jssrcnote);
|
2023-07-12 13:27:26 +10:00
|
|
|
|
2025-02-05 12:40:54 +10:00
|
|
|
script = (JSScript *) cx->malloc(size);
|
2018-09-08 18:08:48 +08:00
|
|
|
if (!script)
|
|
|
|
|
return NULL;
|
2025-03-19 21:25:58 +10:00
|
|
|
|
2025-02-05 12:40:54 +10:00
|
|
|
PodZero(script);
|
2018-09-08 18:08:48 +08:00
|
|
|
script->length = length;
|
2025-03-19 21:25:58 +10:00
|
|
|
script->version = version;
|
|
|
|
|
new (&script->bindings) Bindings(cx);
|
|
|
|
|
|
|
|
|
|
uint8 *scriptEnd = reinterpret_cast<uint8 *>(script + 1);
|
2023-07-12 13:27:26 +10:00
|
|
|
|
2025-03-19 21:25:58 +10:00
|
|
|
cursor = scriptEnd;
|
2023-07-12 13:27:26 +10:00
|
|
|
if (nobjects != 0) {
|
2025-03-19 21:25:58 +10:00
|
|
|
script->objectsOffset = (uint8)(cursor - scriptEnd);
|
2023-07-12 13:27:26 +10:00
|
|
|
cursor += sizeof(JSObjectArray);
|
2025-03-19 21:25:58 +10:00
|
|
|
} else {
|
|
|
|
|
script->objectsOffset = JSScript::INVALID_OFFSET;
|
2023-07-12 13:27:26 +10:00
|
|
|
}
|
2025-02-03 12:35:24 +10:00
|
|
|
if (nupvars != 0) {
|
2025-03-19 21:25:58 +10:00
|
|
|
script->upvarsOffset = (uint8)(cursor - scriptEnd);
|
2025-02-03 12:35:24 +10:00
|
|
|
cursor += sizeof(JSUpvarArray);
|
2025-03-19 21:25:58 +10:00
|
|
|
} else {
|
|
|
|
|
script->upvarsOffset = JSScript::INVALID_OFFSET;
|
2025-02-03 12:35:24 +10:00
|
|
|
}
|
2023-07-12 13:27:26 +10:00
|
|
|
if (nregexps != 0) {
|
2025-03-19 21:25:58 +10:00
|
|
|
script->regexpsOffset = (uint8)(cursor - scriptEnd);
|
2023-07-12 13:27:26 +10:00
|
|
|
cursor += sizeof(JSObjectArray);
|
2025-03-19 21:25:58 +10:00
|
|
|
} else {
|
|
|
|
|
script->regexpsOffset = JSScript::INVALID_OFFSET;
|
2018-09-08 18:08:48 +08:00
|
|
|
}
|
2023-07-12 13:27:26 +10:00
|
|
|
if (ntrynotes != 0) {
|
2025-03-19 21:25:58 +10:00
|
|
|
script->trynotesOffset = (uint8)(cursor - scriptEnd);
|
2023-07-12 13:27:26 +10:00
|
|
|
cursor += sizeof(JSTryNoteArray);
|
2025-03-19 21:25:58 +10:00
|
|
|
} else {
|
|
|
|
|
script->trynotesOffset = JSScript::INVALID_OFFSET;
|
|
|
|
|
}
|
|
|
|
|
if (nglobals != 0) {
|
|
|
|
|
script->globalsOffset = (uint8)(cursor - scriptEnd);
|
|
|
|
|
cursor += sizeof(GlobalSlotArray);
|
|
|
|
|
} else {
|
|
|
|
|
script->globalsOffset = JSScript::INVALID_OFFSET;
|
2023-07-12 13:27:26 +10:00
|
|
|
}
|
2025-03-19 21:25:58 +10:00
|
|
|
JS_ASSERT(cursor - scriptEnd < 0xFF);
|
|
|
|
|
if (nconsts != 0) {
|
|
|
|
|
script->constOffset = (uint8)(cursor - scriptEnd);
|
|
|
|
|
cursor += sizeof(JSConstArray);
|
|
|
|
|
} else {
|
|
|
|
|
script->constOffset = JSScript::INVALID_OFFSET;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
JS_STATIC_ASSERT(sizeof(JSObjectArray) +
|
|
|
|
|
sizeof(JSUpvarArray) +
|
|
|
|
|
sizeof(JSObjectArray) +
|
|
|
|
|
sizeof(JSTryNoteArray) +
|
|
|
|
|
sizeof(GlobalSlotArray) < 0xFF);
|
2023-07-12 13:27:26 +10:00
|
|
|
|
|
|
|
|
if (natoms != 0) {
|
|
|
|
|
script->atomMap.length = natoms;
|
|
|
|
|
script->atomMap.vector = (JSAtom **)cursor;
|
|
|
|
|
vectorSize = natoms * sizeof(script->atomMap.vector[0]);
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Clear object map's vector so the GC tracing can run when not yet
|
|
|
|
|
* all atoms are copied to the array.
|
|
|
|
|
*/
|
|
|
|
|
memset(cursor, 0, vectorSize);
|
|
|
|
|
cursor += vectorSize;
|
|
|
|
|
}
|
2025-02-03 12:35:24 +10:00
|
|
|
|
2023-07-12 13:27:26 +10:00
|
|
|
if (nobjects != 0) {
|
2025-02-05 12:40:54 +10:00
|
|
|
script->objects()->length = nobjects;
|
|
|
|
|
script->objects()->vector = (JSObject **)cursor;
|
|
|
|
|
vectorSize = nobjects * sizeof(script->objects()->vector[0]);
|
2025-02-03 12:35:24 +10:00
|
|
|
memset(cursor, 0, vectorSize);
|
|
|
|
|
cursor += vectorSize;
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-12 13:27:26 +10:00
|
|
|
if (nregexps != 0) {
|
2025-02-05 12:40:54 +10:00
|
|
|
script->regexps()->length = nregexps;
|
|
|
|
|
script->regexps()->vector = (JSObject **)cursor;
|
|
|
|
|
vectorSize = nregexps * sizeof(script->regexps()->vector[0]);
|
2023-07-12 13:27:26 +10:00
|
|
|
memset(cursor, 0, vectorSize);
|
|
|
|
|
cursor += vectorSize;
|
|
|
|
|
}
|
2025-02-03 12:35:24 +10:00
|
|
|
|
2023-07-12 13:27:26 +10:00
|
|
|
if (ntrynotes != 0) {
|
2025-02-05 12:40:54 +10:00
|
|
|
script->trynotes()->length = ntrynotes;
|
|
|
|
|
script->trynotes()->vector = (JSTryNote *)cursor;
|
|
|
|
|
vectorSize = ntrynotes * sizeof(script->trynotes()->vector[0]);
|
2023-07-12 13:27:26 +10:00
|
|
|
#ifdef DEBUG
|
|
|
|
|
memset(cursor, 0, vectorSize);
|
|
|
|
|
#endif
|
|
|
|
|
cursor += vectorSize;
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-19 21:25:58 +10:00
|
|
|
if (nglobals != 0) {
|
|
|
|
|
script->globals()->length = nglobals;
|
|
|
|
|
script->globals()->vector = (GlobalSlotArray::Entry *)cursor;
|
|
|
|
|
vectorSize = nglobals * sizeof(script->globals()->vector[0]);
|
|
|
|
|
cursor += vectorSize;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (totalClosed != 0) {
|
|
|
|
|
script->nClosedArgs = nClosedArgs;
|
|
|
|
|
script->nClosedVars = nClosedVars;
|
|
|
|
|
script->closedSlots = (uint32 *)cursor;
|
|
|
|
|
cursor += totalClosed * sizeof(uint32);
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-05 12:40:54 +10:00
|
|
|
/*
|
|
|
|
|
* NB: We allocate the vector of uint32 upvar cookies after all vectors of
|
|
|
|
|
* pointers, to avoid misalignment on 64-bit platforms. See bug 514645.
|
|
|
|
|
*/
|
|
|
|
|
if (nupvars != 0) {
|
|
|
|
|
script->upvars()->length = nupvars;
|
2025-03-19 21:25:58 +10:00
|
|
|
script->upvars()->vector = reinterpret_cast<UpvarCookie *>(cursor);
|
2025-02-05 12:40:54 +10:00
|
|
|
vectorSize = nupvars * sizeof(script->upvars()->vector[0]);
|
|
|
|
|
memset(cursor, 0, vectorSize);
|
|
|
|
|
cursor += vectorSize;
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-19 21:25:58 +10:00
|
|
|
/* Must go after other arrays; see constPadding definition. */
|
|
|
|
|
if (nconsts != 0) {
|
|
|
|
|
cursor += constPadding;
|
|
|
|
|
script->consts()->length = nconsts;
|
|
|
|
|
script->consts()->vector = (Value *)cursor;
|
|
|
|
|
JS_ASSERT((size_t)cursor % sizeof(double) == 0);
|
|
|
|
|
vectorSize = nconsts * sizeof(script->consts()->vector[0]);
|
|
|
|
|
memset(cursor, 0, vectorSize);
|
|
|
|
|
cursor += vectorSize;
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-12 13:27:26 +10:00
|
|
|
script->code = script->main = (jsbytecode *)cursor;
|
|
|
|
|
JS_ASSERT(cursor +
|
|
|
|
|
length * sizeof(jsbytecode) +
|
|
|
|
|
nsrcnotes * sizeof(jssrcnote) ==
|
|
|
|
|
(uint8 *)script + size);
|
|
|
|
|
|
2025-03-19 21:25:58 +10:00
|
|
|
script->compartment = cx->compartment;
|
2023-07-12 13:27:26 +10:00
|
|
|
#ifdef CHECK_SCRIPT_OWNER
|
|
|
|
|
script->owner = cx->thread;
|
|
|
|
|
#endif
|
2025-03-19 21:25:58 +10:00
|
|
|
|
|
|
|
|
JS_APPEND_LINK(&script->links, &cx->compartment->scripts);
|
|
|
|
|
JS_ASSERT(script->getVersion() == version);
|
2018-09-08 18:08:48 +08:00
|
|
|
return script;
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-12 13:27:26 +10:00
|
|
|
JSScript *
|
2025-03-19 21:25:58 +10:00
|
|
|
JSScript::NewScriptFromCG(JSContext *cx, JSCodeGenerator *cg)
|
2018-09-08 18:08:48 +08:00
|
|
|
{
|
2025-02-03 12:35:24 +10:00
|
|
|
uint32 mainLength, prologLength, nsrcnotes, nfixed;
|
2018-09-08 18:08:48 +08:00
|
|
|
JSScript *script;
|
|
|
|
|
const char *filename;
|
2023-07-12 13:27:26 +10:00
|
|
|
JSFunction *fun;
|
|
|
|
|
|
|
|
|
|
/* The counts of indexed things must be checked during code generation. */
|
|
|
|
|
JS_ASSERT(cg->atomList.count <= INDEX_LIMIT);
|
|
|
|
|
JS_ASSERT(cg->objectList.length <= INDEX_LIMIT);
|
|
|
|
|
JS_ASSERT(cg->regexpList.length <= INDEX_LIMIT);
|
2018-09-08 18:08:48 +08:00
|
|
|
|
|
|
|
|
mainLength = CG_OFFSET(cg);
|
|
|
|
|
prologLength = CG_PROLOG_OFFSET(cg);
|
2025-02-05 12:40:54 +10:00
|
|
|
|
2018-09-08 18:08:48 +08:00
|
|
|
CG_COUNT_FINAL_SRCNOTES(cg, nsrcnotes);
|
2025-03-19 21:25:58 +10:00
|
|
|
uint16 nClosedArgs = uint16(cg->closedArgs.length());
|
|
|
|
|
JS_ASSERT(nClosedArgs == cg->closedArgs.length());
|
|
|
|
|
uint16 nClosedVars = uint16(cg->closedVars.length());
|
|
|
|
|
JS_ASSERT(nClosedVars == cg->closedVars.length());
|
|
|
|
|
script = NewScript(cx, prologLength + mainLength, nsrcnotes,
|
|
|
|
|
cg->atomList.count, cg->objectList.length,
|
|
|
|
|
cg->upvarList.count, cg->regexpList.length,
|
|
|
|
|
cg->ntrynotes, cg->constList.length(),
|
|
|
|
|
cg->globalUses.length(), nClosedArgs, nClosedVars, cg->version());
|
2018-09-08 18:08:48 +08:00
|
|
|
if (!script)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
/* Now that we have script, error control flow must go to label bad. */
|
|
|
|
|
script->main += prologLength;
|
|
|
|
|
memcpy(script->code, CG_PROLOG_BASE(cg), prologLength * sizeof(jsbytecode));
|
|
|
|
|
memcpy(script->main, CG_BASE(cg), mainLength * sizeof(jsbytecode));
|
2025-03-19 21:25:58 +10:00
|
|
|
nfixed = cg->inFunction()
|
|
|
|
|
? cg->bindings.countVars()
|
|
|
|
|
: cg->sharpSlots();
|
2025-02-03 12:35:24 +10:00
|
|
|
JS_ASSERT(nfixed < SLOTNO_LIMIT);
|
|
|
|
|
script->nfixed = (uint16) nfixed;
|
2023-07-12 13:27:26 +10:00
|
|
|
js_InitAtomMap(cx, &script->atomMap, &cg->atomList);
|
|
|
|
|
|
2025-02-05 12:40:54 +10:00
|
|
|
filename = cg->parser->tokenStream.getFilename();
|
2018-09-08 18:08:48 +08:00
|
|
|
if (filename) {
|
|
|
|
|
script->filename = js_SaveScriptFilename(cx, filename);
|
|
|
|
|
if (!script->filename)
|
|
|
|
|
goto bad;
|
|
|
|
|
}
|
|
|
|
|
script->lineno = cg->firstLine;
|
2025-02-03 12:35:24 +10:00
|
|
|
if (script->nfixed + cg->maxStackDepth >= JS_BIT(16)) {
|
2025-02-05 12:40:54 +10:00
|
|
|
ReportCompileErrorNumber(cx, CG_TS(cg), NULL, JSREPORT_ERROR, JSMSG_NEED_DIET, "script");
|
2025-02-03 12:35:24 +10:00
|
|
|
goto bad;
|
|
|
|
|
}
|
|
|
|
|
script->nslots = script->nfixed + cg->maxStackDepth;
|
2025-02-05 12:40:54 +10:00
|
|
|
script->staticLevel = uint16(cg->staticLevel);
|
|
|
|
|
script->principals = cg->parser->principals;
|
2023-07-12 13:27:26 +10:00
|
|
|
if (script->principals)
|
2018-09-08 18:08:48 +08:00
|
|
|
JSPRINCIPALS_HOLD(cx, script->principals);
|
|
|
|
|
|
2025-02-05 12:40:54 +10:00
|
|
|
if (!js_FinishTakingSrcNotes(cx, cg, script->notes()))
|
2018-09-08 18:08:48 +08:00
|
|
|
goto bad;
|
2023-07-12 13:27:26 +10:00
|
|
|
if (cg->ntrynotes != 0)
|
2025-02-05 12:40:54 +10:00
|
|
|
js_FinishTakingTryNotes(cg, script->trynotes());
|
2023-07-12 13:27:26 +10:00
|
|
|
if (cg->objectList.length != 0)
|
2025-02-05 12:40:54 +10:00
|
|
|
cg->objectList.finish(script->objects());
|
2023-07-12 13:27:26 +10:00
|
|
|
if (cg->regexpList.length != 0)
|
2025-02-05 12:40:54 +10:00
|
|
|
cg->regexpList.finish(script->regexps());
|
2025-03-19 21:25:58 +10:00
|
|
|
if (cg->constList.length() != 0)
|
|
|
|
|
cg->constList.finish(script->consts());
|
2025-02-05 12:40:54 +10:00
|
|
|
if (cg->flags & TCF_NO_SCRIPT_RVAL)
|
|
|
|
|
script->noScriptRval = true;
|
|
|
|
|
if (cg->hasSharps())
|
|
|
|
|
script->hasSharps = true;
|
|
|
|
|
if (cg->flags & TCF_STRICT_MODE_CODE)
|
|
|
|
|
script->strictModeCode = true;
|
2025-03-19 21:25:58 +10:00
|
|
|
if (cg->flags & TCF_COMPILE_N_GO)
|
|
|
|
|
script->compileAndGo = true;
|
|
|
|
|
if (cg->callsEval())
|
|
|
|
|
script->usesEval = true;
|
|
|
|
|
if (cg->flags & TCF_FUN_USES_ARGUMENTS)
|
|
|
|
|
script->usesArguments = true;
|
|
|
|
|
if (cg->flags & TCF_HAS_SINGLETONS)
|
|
|
|
|
script->hasSingletons = true;
|
2025-02-03 12:35:24 +10:00
|
|
|
|
|
|
|
|
if (cg->upvarList.count != 0) {
|
|
|
|
|
JS_ASSERT(cg->upvarList.count <= cg->upvarMap.length);
|
2025-02-05 12:40:54 +10:00
|
|
|
memcpy(script->upvars()->vector, cg->upvarMap.vector,
|
2025-02-03 12:35:24 +10:00
|
|
|
cg->upvarList.count * sizeof(uint32));
|
2025-02-05 12:40:54 +10:00
|
|
|
cg->upvarList.clear();
|
|
|
|
|
cx->free(cg->upvarMap.vector);
|
2025-02-03 12:35:24 +10:00
|
|
|
cg->upvarMap.vector = NULL;
|
|
|
|
|
}
|
2018-09-08 18:08:48 +08:00
|
|
|
|
2025-03-19 21:25:58 +10:00
|
|
|
if (cg->globalUses.length()) {
|
|
|
|
|
memcpy(script->globals()->vector, &cg->globalUses[0],
|
|
|
|
|
cg->globalUses.length() * sizeof(GlobalSlotArray::Entry));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (script->nClosedArgs)
|
|
|
|
|
memcpy(script->closedSlots, &cg->closedArgs[0], script->nClosedArgs * sizeof(uint32));
|
|
|
|
|
if (script->nClosedVars) {
|
|
|
|
|
memcpy(&script->closedSlots[script->nClosedArgs], &cg->closedVars[0],
|
|
|
|
|
script->nClosedVars * sizeof(uint32));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cg->bindings.makeImmutable();
|
|
|
|
|
script->bindings.transfer(cx, &cg->bindings);
|
|
|
|
|
|
Numerous changes with focus on feature and stability parity across Windows, Linux and MacOS platforms
Added new Makefile that handles compiling UOX3 and Spidermonkey on both Linux and MacOS (punt)
Added VS solution (SpiderMonkey.sln) and VC++ project files for compiling SpiderMonkey on Windows (Xuri)
Updated SpiderMonkey from v1.6.0 to v1.7.0
Added optimization flag -O2 for release build in CMakeLists.txt in project root (Xuri)
Added StringUtility file with general common string manipulation functions (punt)
Updated RandomNum function to use a "seedless" random number generator from C++11 instead of the old C rand() function. (punt)
Overall code cleanup to remove/replace platform-dependent code (punt)
Replaced potentially unsafe usage of C string stuff like sprintf, vsprintf, vsnprintf, strncat, strcpy and strlen throughout the code with calls to a format() function containing only a single, safe use of vsnprintf, ensuring there's a single place of failure if there's anything to fix and and making it easy to potentially replace this with std::format from C++20 when the time comes. (punt)
Replaced usage of char in many places with std::string (punt)
Started process of replacing UString usage with functions provided through StringUtility instead (punt)
Replaced platform specific fileIO handling in Windows/Linux with cross-platform C++17 standard std::filesystem (punt)
Replaced platform specific time handling by using cross-platform chrono library (punt)
Removed UOX namespace to reduce complexity (punt)
Elimitated template code approach to singletons for more modern c++ constructs, removing dependices in the process (punt)
Removed ODBC support; it hasn't been touched since the initial implementation in 2008, and there is a lack of someone to maintain the code. (punt)
Removed some platform specific files like uoxlinux.h, which is no longer required (punt)
Removed legacy crash protection code, and removed support for cluox (punt)
Removed legacy "support" for Borland compiler (punt)
Removed legacy VC++ 6 Workspace/Project files, VS2005 Solution/Project files, as these are no longer supported (Xuri)
Removed legacy BUILD folder with outdated compilation instructions (Xuri)
Removed old Changelog file (merged into Changelog.txt) (Xuri)
Fixed a pointer bug for items in multis on world load (punt)
Fixed a dictionary related issue that caused segmentation faults on Linux/MacOS (punt)
Fixed an issue with callbacks to JS scripts that caused segmentation faults on Linux/MacOS (punt)
Paths in uox.ini should now load properly on all platforms regardless of whether those paths use slashes or backslashes, and whether or not they end in a slash/backslash. (punt)
Moved to c++17 style of threading, and got rid of threadsafeobject.cpp/h (punt)
Replaced parsing of UOX.INI tags with a system that's more easily maintainable (punt)
Added some new commands to js/commands/custom/misc-cmd.js (Xuri)
cont // Targeted item will be made a container, set to nondecay and movable 2
endfight // Targeted character (and character being fought) will stop fighting
getmulti // Get multiObject for targeted item
finditem // Find item at layer X
movespeed // Set movement speed of target player (0x0 Normal, 0x1 Mounted, 0x2 Slow (walk only), 0x3 Hybrid ("jog"?), 0x4 Frozen)
Added new HTML based documentation in docs folder, and removed many old legacy docs that are either incorporated into this document already or no longer relevant for the current UOX3 version (Xuri)
Co-Authored-By: Charles Kerr <punt1959@users.noreply.github.com>
2020-09-07 18:09:55 +08:00
|
|
|
/*
|
|
|
|
|
* We initialize fun->u.script to be the script constructed above
|
|
|
|
|
* so that the debugger has a valid FUN_SCRIPT(fun).
|
|
|
|
|
*/
|
2023-07-12 13:27:26 +10:00
|
|
|
fun = NULL;
|
2025-03-19 21:25:58 +10:00
|
|
|
if (cg->inFunction()) {
|
|
|
|
|
fun = cg->fun();
|
|
|
|
|
JS_ASSERT(fun->isInterpreted());
|
|
|
|
|
JS_ASSERT(!fun->script());
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
|
if (JSScript::isValidOffset(script->upvarsOffset))
|
|
|
|
|
JS_ASSERT(script->upvars()->length == script->bindings.countUpvars());
|
2025-02-05 12:40:54 +10:00
|
|
|
else
|
2025-03-19 21:25:58 +10:00
|
|
|
JS_ASSERT(script->bindings.countUpvars() == 0);
|
|
|
|
|
#endif
|
Numerous changes with focus on feature and stability parity across Windows, Linux and MacOS platforms
Added new Makefile that handles compiling UOX3 and Spidermonkey on both Linux and MacOS (punt)
Added VS solution (SpiderMonkey.sln) and VC++ project files for compiling SpiderMonkey on Windows (Xuri)
Updated SpiderMonkey from v1.6.0 to v1.7.0
Added optimization flag -O2 for release build in CMakeLists.txt in project root (Xuri)
Added StringUtility file with general common string manipulation functions (punt)
Updated RandomNum function to use a "seedless" random number generator from C++11 instead of the old C rand() function. (punt)
Overall code cleanup to remove/replace platform-dependent code (punt)
Replaced potentially unsafe usage of C string stuff like sprintf, vsprintf, vsnprintf, strncat, strcpy and strlen throughout the code with calls to a format() function containing only a single, safe use of vsnprintf, ensuring there's a single place of failure if there's anything to fix and and making it easy to potentially replace this with std::format from C++20 when the time comes. (punt)
Replaced usage of char in many places with std::string (punt)
Started process of replacing UString usage with functions provided through StringUtility instead (punt)
Replaced platform specific fileIO handling in Windows/Linux with cross-platform C++17 standard std::filesystem (punt)
Replaced platform specific time handling by using cross-platform chrono library (punt)
Removed UOX namespace to reduce complexity (punt)
Elimitated template code approach to singletons for more modern c++ constructs, removing dependices in the process (punt)
Removed ODBC support; it hasn't been touched since the initial implementation in 2008, and there is a lack of someone to maintain the code. (punt)
Removed some platform specific files like uoxlinux.h, which is no longer required (punt)
Removed legacy crash protection code, and removed support for cluox (punt)
Removed legacy "support" for Borland compiler (punt)
Removed legacy VC++ 6 Workspace/Project files, VS2005 Solution/Project files, as these are no longer supported (Xuri)
Removed legacy BUILD folder with outdated compilation instructions (Xuri)
Removed old Changelog file (merged into Changelog.txt) (Xuri)
Fixed a pointer bug for items in multis on world load (punt)
Fixed a dictionary related issue that caused segmentation faults on Linux/MacOS (punt)
Fixed an issue with callbacks to JS scripts that caused segmentation faults on Linux/MacOS (punt)
Paths in uox.ini should now load properly on all platforms regardless of whether those paths use slashes or backslashes, and whether or not they end in a slash/backslash. (punt)
Moved to c++17 style of threading, and got rid of threadsafeobject.cpp/h (punt)
Replaced parsing of UOX.INI tags with a system that's more easily maintainable (punt)
Added some new commands to js/commands/custom/misc-cmd.js (Xuri)
cont // Targeted item will be made a container, set to nondecay and movable 2
endfight // Targeted character (and character being fought) will stop fighting
getmulti // Get multiObject for targeted item
finditem // Find item at layer X
movespeed // Set movement speed of target player (0x0 Normal, 0x1 Mounted, 0x2 Slow (walk only), 0x3 Hybrid ("jog"?), 0x4 Frozen)
Added new HTML based documentation in docs folder, and removed many old legacy docs that are either incorporated into this document already or no longer relevant for the current UOX3 version (Xuri)
Co-Authored-By: Charles Kerr <punt1959@users.noreply.github.com>
2020-09-07 18:09:55 +08:00
|
|
|
fun->u.i.script = script;
|
2023-07-12 13:27:26 +10:00
|
|
|
#ifdef CHECK_SCRIPT_OWNER
|
|
|
|
|
script->owner = NULL;
|
|
|
|
|
#endif
|
2025-02-05 12:40:54 +10:00
|
|
|
if (cg->flags & TCF_FUN_HEAVYWEIGHT)
|
Numerous changes with focus on feature and stability parity across Windows, Linux and MacOS platforms
Added new Makefile that handles compiling UOX3 and Spidermonkey on both Linux and MacOS (punt)
Added VS solution (SpiderMonkey.sln) and VC++ project files for compiling SpiderMonkey on Windows (Xuri)
Updated SpiderMonkey from v1.6.0 to v1.7.0
Added optimization flag -O2 for release build in CMakeLists.txt in project root (Xuri)
Added StringUtility file with general common string manipulation functions (punt)
Updated RandomNum function to use a "seedless" random number generator from C++11 instead of the old C rand() function. (punt)
Overall code cleanup to remove/replace platform-dependent code (punt)
Replaced potentially unsafe usage of C string stuff like sprintf, vsprintf, vsnprintf, strncat, strcpy and strlen throughout the code with calls to a format() function containing only a single, safe use of vsnprintf, ensuring there's a single place of failure if there's anything to fix and and making it easy to potentially replace this with std::format from C++20 when the time comes. (punt)
Replaced usage of char in many places with std::string (punt)
Started process of replacing UString usage with functions provided through StringUtility instead (punt)
Replaced platform specific fileIO handling in Windows/Linux with cross-platform C++17 standard std::filesystem (punt)
Replaced platform specific time handling by using cross-platform chrono library (punt)
Removed UOX namespace to reduce complexity (punt)
Elimitated template code approach to singletons for more modern c++ constructs, removing dependices in the process (punt)
Removed ODBC support; it hasn't been touched since the initial implementation in 2008, and there is a lack of someone to maintain the code. (punt)
Removed some platform specific files like uoxlinux.h, which is no longer required (punt)
Removed legacy crash protection code, and removed support for cluox (punt)
Removed legacy "support" for Borland compiler (punt)
Removed legacy VC++ 6 Workspace/Project files, VS2005 Solution/Project files, as these are no longer supported (Xuri)
Removed legacy BUILD folder with outdated compilation instructions (Xuri)
Removed old Changelog file (merged into Changelog.txt) (Xuri)
Fixed a pointer bug for items in multis on world load (punt)
Fixed a dictionary related issue that caused segmentation faults on Linux/MacOS (punt)
Fixed an issue with callbacks to JS scripts that caused segmentation faults on Linux/MacOS (punt)
Paths in uox.ini should now load properly on all platforms regardless of whether those paths use slashes or backslashes, and whether or not they end in a slash/backslash. (punt)
Moved to c++17 style of threading, and got rid of threadsafeobject.cpp/h (punt)
Replaced parsing of UOX.INI tags with a system that's more easily maintainable (punt)
Added some new commands to js/commands/custom/misc-cmd.js (Xuri)
cont // Targeted item will be made a container, set to nondecay and movable 2
endfight // Targeted character (and character being fought) will stop fighting
getmulti // Get multiObject for targeted item
finditem // Find item at layer X
movespeed // Set movement speed of target player (0x0 Normal, 0x1 Mounted, 0x2 Slow (walk only), 0x3 Hybrid ("jog"?), 0x4 Frozen)
Added new HTML based documentation in docs folder, and removed many old legacy docs that are either incorporated into this document already or no longer relevant for the current UOX3 version (Xuri)
Co-Authored-By: Charles Kerr <punt1959@users.noreply.github.com>
2020-09-07 18:09:55 +08:00
|
|
|
fun->flags |= JSFUN_HEAVYWEIGHT;
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-08 18:08:48 +08:00
|
|
|
/* Tell the debugger about this compiled script. */
|
|
|
|
|
js_CallNewScriptHook(cx, script, fun);
|
2025-03-19 21:25:58 +10:00
|
|
|
#ifdef DEBUG
|
|
|
|
|
{
|
|
|
|
|
jsrefcount newEmptyLive, newLive, newTotal;
|
|
|
|
|
if (script->isEmpty()) {
|
|
|
|
|
newEmptyLive = JS_RUNTIME_METER(cx->runtime, liveEmptyScripts);
|
|
|
|
|
newLive = cx->runtime->liveScripts;
|
|
|
|
|
newTotal =
|
|
|
|
|
JS_RUNTIME_METER(cx->runtime, totalEmptyScripts) + cx->runtime->totalScripts;
|
|
|
|
|
} else {
|
|
|
|
|
newEmptyLive = cx->runtime->liveEmptyScripts;
|
|
|
|
|
newLive = JS_RUNTIME_METER(cx->runtime, liveScripts);
|
|
|
|
|
newTotal =
|
|
|
|
|
cx->runtime->totalEmptyScripts + JS_RUNTIME_METER(cx->runtime, totalScripts);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
jsrefcount oldHigh = cx->runtime->highWaterLiveScripts;
|
|
|
|
|
if (newEmptyLive + newLive > oldHigh) {
|
|
|
|
|
JS_ATOMIC_SET(&cx->runtime->highWaterLiveScripts, newEmptyLive + newLive);
|
|
|
|
|
if (getenv("JS_DUMP_LIVE_SCRIPTS")) {
|
|
|
|
|
fprintf(stderr, "high water script count: %d empty, %d not (total %d)\n",
|
|
|
|
|
newEmptyLive, newLive, newTotal);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2018-09-08 18:08:48 +08:00
|
|
|
return script;
|
|
|
|
|
|
|
|
|
|
bad:
|
|
|
|
|
js_DestroyScript(cx, script);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
JS_FRIEND_API(void)
|
|
|
|
|
js_CallNewScriptHook(JSContext *cx, JSScript *script, JSFunction *fun)
|
|
|
|
|
{
|
|
|
|
|
JSNewScriptHook hook;
|
|
|
|
|
|
2023-07-12 13:27:26 +10:00
|
|
|
hook = cx->debugHooks->newScriptHook;
|
2018-09-08 18:08:48 +08:00
|
|
|
if (hook) {
|
2025-02-05 12:40:54 +10:00
|
|
|
AutoKeepAtoms keep(cx->runtime);
|
2018-09-08 18:08:48 +08:00
|
|
|
hook(cx, script->filename, script->lineno, script, fun,
|
2023-07-12 13:27:26 +10:00
|
|
|
cx->debugHooks->newScriptHookData);
|
2018-09-08 18:08:48 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-19 21:25:58 +10:00
|
|
|
void
|
2018-09-08 18:08:48 +08:00
|
|
|
js_CallDestroyScriptHook(JSContext *cx, JSScript *script)
|
|
|
|
|
{
|
|
|
|
|
JSDestroyScriptHook hook;
|
|
|
|
|
|
2023-07-12 13:27:26 +10:00
|
|
|
hook = cx->debugHooks->destroyScriptHook;
|
2018-09-08 18:08:48 +08:00
|
|
|
if (hook)
|
2023-07-12 13:27:26 +10:00
|
|
|
hook(cx, script, cx->debugHooks->destroyScriptHookData);
|
2025-03-19 21:25:58 +10:00
|
|
|
JS_ClearScriptTraps(cx, script);
|
2018-09-08 18:08:48 +08:00
|
|
|
}
|
|
|
|
|
|
2025-03-19 21:25:58 +10:00
|
|
|
static void
|
|
|
|
|
DestroyScript(JSContext *cx, JSScript *script)
|
2018-09-08 18:08:48 +08:00
|
|
|
{
|
2025-03-19 21:25:58 +10:00
|
|
|
#ifdef DEBUG
|
|
|
|
|
if (script->isEmpty())
|
2025-02-05 12:40:54 +10:00
|
|
|
JS_RUNTIME_UNMETER(cx->runtime, liveEmptyScripts);
|
2025-03-19 21:25:58 +10:00
|
|
|
else
|
|
|
|
|
JS_RUNTIME_UNMETER(cx->runtime, liveScripts);
|
|
|
|
|
#endif
|
2023-07-12 13:27:26 +10:00
|
|
|
|
2018-09-08 18:08:48 +08:00
|
|
|
if (script->principals)
|
|
|
|
|
JSPRINCIPALS_DROP(cx, script->principals);
|
2023-07-12 13:27:26 +10:00
|
|
|
|
|
|
|
|
if (JS_GSN_CACHE(cx).code == script->code)
|
2025-02-05 12:40:54 +10:00
|
|
|
JS_PURGE_GSN_CACHE(cx);
|
2023-07-12 13:27:26 +10:00
|
|
|
|
|
|
|
|
/*
|
2025-02-05 12:40:54 +10:00
|
|
|
* Worry about purging the property cache and any compiled traces related
|
|
|
|
|
* to its bytecode if this script is being destroyed from JS_DestroyScript
|
|
|
|
|
* or equivalent according to a mandatory "New/Destroy" protocol.
|
|
|
|
|
*
|
|
|
|
|
* The GC purges all property caches when regenerating shapes upon shape
|
|
|
|
|
* generator overflow, so no need in that event to purge just the entries
|
|
|
|
|
* for this script.
|
|
|
|
|
*
|
|
|
|
|
* The GC purges trace-JITted code on every GC activation, not just when
|
|
|
|
|
* regenerating shapes, so we don't have to purge fragments if the GC is
|
|
|
|
|
* currently running.
|
2023-07-12 13:27:26 +10:00
|
|
|
*
|
2025-02-05 12:40:54 +10:00
|
|
|
* JS_THREADSAFE note: The code below purges only the current thread's
|
|
|
|
|
* property cache, so a script not owned by a function or object, which
|
|
|
|
|
* hands off lifetime management for that script to the GC, must be used by
|
|
|
|
|
* only one thread over its lifetime.
|
2023-07-12 13:27:26 +10:00
|
|
|
*
|
|
|
|
|
* This should be an API-compatible change, since a script is never safe
|
|
|
|
|
* against premature GC if shared among threads without a rooted object
|
|
|
|
|
* wrapping it to protect the script's mapped atoms against GC. We use
|
|
|
|
|
* script->owner to enforce this requirement via assertions.
|
|
|
|
|
*/
|
|
|
|
|
#ifdef CHECK_SCRIPT_OWNER
|
|
|
|
|
JS_ASSERT_IF(cx->runtime->gcRunning, !script->owner);
|
|
|
|
|
#endif
|
|
|
|
|
|
2025-02-05 12:40:54 +10:00
|
|
|
/* FIXME: bug 506341; would like to do this only if regenerating shapes. */
|
2025-02-03 12:35:24 +10:00
|
|
|
if (!cx->runtime->gcRunning) {
|
2025-02-05 12:40:54 +10:00
|
|
|
JSStackFrame *fp = js_GetTopStackFrame(cx);
|
|
|
|
|
|
2025-03-19 21:25:58 +10:00
|
|
|
if (!(fp && fp->isEvalFrame())) {
|
2025-02-05 12:40:54 +10:00
|
|
|
JS_PROPERTY_CACHE(cx).purgeForScript(script);
|
|
|
|
|
|
2023-07-12 13:27:26 +10:00
|
|
|
#ifdef CHECK_SCRIPT_OWNER
|
2025-02-03 12:35:24 +10:00
|
|
|
JS_ASSERT(script->owner == cx->thread);
|
2023-07-12 13:27:26 +10:00
|
|
|
#endif
|
2025-02-03 12:35:24 +10:00
|
|
|
}
|
2023-07-12 13:27:26 +10:00
|
|
|
}
|
|
|
|
|
|
2025-02-05 12:40:54 +10:00
|
|
|
#ifdef JS_TRACER
|
2025-03-19 21:25:58 +10:00
|
|
|
PurgeScriptFragments(&script->compartment->traceMonitor, script);
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#if defined(JS_METHODJIT)
|
|
|
|
|
mjit::ReleaseScriptCode(cx, script);
|
2025-02-05 12:40:54 +10:00
|
|
|
#endif
|
2025-03-19 21:25:58 +10:00
|
|
|
JS_REMOVE_LINK(&script->links);
|
2025-02-05 12:40:54 +10:00
|
|
|
|
|
|
|
|
cx->free(script);
|
2025-03-19 21:25:58 +10:00
|
|
|
}
|
2025-02-05 12:40:54 +10:00
|
|
|
|
2025-03-19 21:25:58 +10:00
|
|
|
void
|
|
|
|
|
js_DestroyScript(JSContext *cx, JSScript *script)
|
|
|
|
|
{
|
|
|
|
|
JS_ASSERT(!cx->runtime->gcRunning);
|
|
|
|
|
js_CallDestroyScriptHook(cx, script);
|
|
|
|
|
DestroyScript(cx, script);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
js_DestroyScriptFromGC(JSContext *cx, JSScript *script)
|
|
|
|
|
{
|
|
|
|
|
JS_ASSERT(cx->runtime->gcRunning);
|
|
|
|
|
js_CallDestroyScriptHook(cx, script);
|
|
|
|
|
DestroyScript(cx, script);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
js_DestroyCachedScript(JSContext *cx, JSScript *script)
|
|
|
|
|
{
|
|
|
|
|
JS_ASSERT(cx->runtime->gcRunning);
|
|
|
|
|
DestroyScript(cx, script);
|
2018-09-08 18:08:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2023-07-12 13:27:26 +10:00
|
|
|
js_TraceScript(JSTracer *trc, JSScript *script)
|
2018-09-08 18:08:48 +08:00
|
|
|
{
|
2025-03-19 21:25:58 +10:00
|
|
|
JSAtomMap *map = &script->atomMap;
|
|
|
|
|
MarkAtomRange(trc, map->length, map->vector, "atomMap");
|
2023-07-12 13:27:26 +10:00
|
|
|
|
2025-03-19 21:25:58 +10:00
|
|
|
if (JSScript::isValidOffset(script->objectsOffset)) {
|
|
|
|
|
JSObjectArray *objarray = script->objects();
|
|
|
|
|
uintN i = objarray->length;
|
2023-07-12 13:27:26 +10:00
|
|
|
do {
|
|
|
|
|
--i;
|
|
|
|
|
if (objarray->vector[i]) {
|
|
|
|
|
JS_SET_TRACING_INDEX(trc, "objects", i);
|
2025-03-19 21:25:58 +10:00
|
|
|
Mark(trc, objarray->vector[i]);
|
2023-07-12 13:27:26 +10:00
|
|
|
}
|
|
|
|
|
} while (i != 0);
|
|
|
|
|
}
|
2018-09-08 18:08:48 +08:00
|
|
|
|
2025-03-19 21:25:58 +10:00
|
|
|
if (JSScript::isValidOffset(script->regexpsOffset)) {
|
|
|
|
|
JSObjectArray *objarray = script->regexps();
|
|
|
|
|
uintN i = objarray->length;
|
2023-07-12 13:27:26 +10:00
|
|
|
do {
|
|
|
|
|
--i;
|
|
|
|
|
if (objarray->vector[i]) {
|
|
|
|
|
JS_SET_TRACING_INDEX(trc, "regexps", i);
|
2025-03-19 21:25:58 +10:00
|
|
|
Mark(trc, objarray->vector[i]);
|
2023-07-12 13:27:26 +10:00
|
|
|
}
|
|
|
|
|
} while (i != 0);
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-19 21:25:58 +10:00
|
|
|
if (JSScript::isValidOffset(script->constOffset)) {
|
|
|
|
|
JSConstArray *constarray = script->consts();
|
|
|
|
|
MarkValueRange(trc, constarray->length, constarray->vector, "consts");
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-03 12:35:24 +10:00
|
|
|
if (script->u.object) {
|
|
|
|
|
JS_SET_TRACING_NAME(trc, "object");
|
2025-03-19 21:25:58 +10:00
|
|
|
Mark(trc, script->u.object);
|
2025-02-03 12:35:24 +10:00
|
|
|
}
|
|
|
|
|
|
2023-07-12 13:27:26 +10:00
|
|
|
if (IS_GC_MARKING_TRACER(trc) && script->filename)
|
2018-09-08 18:08:48 +08:00
|
|
|
js_MarkScriptFilename(script->filename);
|
2025-03-19 21:25:58 +10:00
|
|
|
|
|
|
|
|
script->bindings.trace(trc);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
JSBool
|
|
|
|
|
js_NewScriptObject(JSContext *cx, JSScript *script)
|
|
|
|
|
{
|
|
|
|
|
AutoScriptRooter root(cx, script);
|
|
|
|
|
|
|
|
|
|
JS_ASSERT(!script->u.object);
|
|
|
|
|
|
|
|
|
|
JSObject *obj = NewNonFunction<WithProto::Class>(cx, &js_ScriptClass, NULL, NULL);
|
|
|
|
|
if (!obj)
|
|
|
|
|
return JS_FALSE;
|
|
|
|
|
obj->setPrivate(script);
|
|
|
|
|
script->u.object = obj;
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Clear the object's proto, to avoid entraining stuff. Once we no longer use the parent
|
|
|
|
|
* for security checks, then we can clear the parent, too.
|
|
|
|
|
*/
|
|
|
|
|
obj->clearProto();
|
|
|
|
|
|
|
|
|
|
#ifdef CHECK_SCRIPT_OWNER
|
|
|
|
|
script->owner = NULL;
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
return JS_TRUE;
|
2018-09-08 18:08:48 +08:00
|
|
|
}
|
|
|
|
|
|
Numerous changes with focus on feature and stability parity across Windows, Linux and MacOS platforms
Added new Makefile that handles compiling UOX3 and Spidermonkey on both Linux and MacOS (punt)
Added VS solution (SpiderMonkey.sln) and VC++ project files for compiling SpiderMonkey on Windows (Xuri)
Updated SpiderMonkey from v1.6.0 to v1.7.0
Added optimization flag -O2 for release build in CMakeLists.txt in project root (Xuri)
Added StringUtility file with general common string manipulation functions (punt)
Updated RandomNum function to use a "seedless" random number generator from C++11 instead of the old C rand() function. (punt)
Overall code cleanup to remove/replace platform-dependent code (punt)
Replaced potentially unsafe usage of C string stuff like sprintf, vsprintf, vsnprintf, strncat, strcpy and strlen throughout the code with calls to a format() function containing only a single, safe use of vsnprintf, ensuring there's a single place of failure if there's anything to fix and and making it easy to potentially replace this with std::format from C++20 when the time comes. (punt)
Replaced usage of char in many places with std::string (punt)
Started process of replacing UString usage with functions provided through StringUtility instead (punt)
Replaced platform specific fileIO handling in Windows/Linux with cross-platform C++17 standard std::filesystem (punt)
Replaced platform specific time handling by using cross-platform chrono library (punt)
Removed UOX namespace to reduce complexity (punt)
Elimitated template code approach to singletons for more modern c++ constructs, removing dependices in the process (punt)
Removed ODBC support; it hasn't been touched since the initial implementation in 2008, and there is a lack of someone to maintain the code. (punt)
Removed some platform specific files like uoxlinux.h, which is no longer required (punt)
Removed legacy crash protection code, and removed support for cluox (punt)
Removed legacy "support" for Borland compiler (punt)
Removed legacy VC++ 6 Workspace/Project files, VS2005 Solution/Project files, as these are no longer supported (Xuri)
Removed legacy BUILD folder with outdated compilation instructions (Xuri)
Removed old Changelog file (merged into Changelog.txt) (Xuri)
Fixed a pointer bug for items in multis on world load (punt)
Fixed a dictionary related issue that caused segmentation faults on Linux/MacOS (punt)
Fixed an issue with callbacks to JS scripts that caused segmentation faults on Linux/MacOS (punt)
Paths in uox.ini should now load properly on all platforms regardless of whether those paths use slashes or backslashes, and whether or not they end in a slash/backslash. (punt)
Moved to c++17 style of threading, and got rid of threadsafeobject.cpp/h (punt)
Replaced parsing of UOX.INI tags with a system that's more easily maintainable (punt)
Added some new commands to js/commands/custom/misc-cmd.js (Xuri)
cont // Targeted item will be made a container, set to nondecay and movable 2
endfight // Targeted character (and character being fought) will stop fighting
getmulti // Get multiObject for targeted item
finditem // Find item at layer X
movespeed // Set movement speed of target player (0x0 Normal, 0x1 Mounted, 0x2 Slow (walk only), 0x3 Hybrid ("jog"?), 0x4 Frozen)
Added new HTML based documentation in docs folder, and removed many old legacy docs that are either incorporated into this document already or no longer relevant for the current UOX3 version (Xuri)
Co-Authored-By: Charles Kerr <punt1959@users.noreply.github.com>
2020-09-07 18:09:55 +08:00
|
|
|
typedef struct GSNCacheEntry {
|
|
|
|
|
JSDHashEntryHdr hdr;
|
|
|
|
|
jsbytecode *pc;
|
|
|
|
|
jssrcnote *sn;
|
|
|
|
|
} GSNCacheEntry;
|
|
|
|
|
|
|
|
|
|
#define GSN_CACHE_THRESHOLD 100
|
|
|
|
|
|
2025-02-05 12:40:54 +10:00
|
|
|
void
|
|
|
|
|
js_PurgeGSNCache(JSGSNCache *cache)
|
|
|
|
|
{
|
|
|
|
|
cache->code = NULL;
|
|
|
|
|
if (cache->table.ops) {
|
|
|
|
|
JS_DHashTableFinish(&cache->table);
|
|
|
|
|
cache->table.ops = NULL;
|
|
|
|
|
}
|
|
|
|
|
GSN_CACHE_METER(cache, purges);
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-08 18:08:48 +08:00
|
|
|
jssrcnote *
|
Numerous changes with focus on feature and stability parity across Windows, Linux and MacOS platforms
Added new Makefile that handles compiling UOX3 and Spidermonkey on both Linux and MacOS (punt)
Added VS solution (SpiderMonkey.sln) and VC++ project files for compiling SpiderMonkey on Windows (Xuri)
Updated SpiderMonkey from v1.6.0 to v1.7.0
Added optimization flag -O2 for release build in CMakeLists.txt in project root (Xuri)
Added StringUtility file with general common string manipulation functions (punt)
Updated RandomNum function to use a "seedless" random number generator from C++11 instead of the old C rand() function. (punt)
Overall code cleanup to remove/replace platform-dependent code (punt)
Replaced potentially unsafe usage of C string stuff like sprintf, vsprintf, vsnprintf, strncat, strcpy and strlen throughout the code with calls to a format() function containing only a single, safe use of vsnprintf, ensuring there's a single place of failure if there's anything to fix and and making it easy to potentially replace this with std::format from C++20 when the time comes. (punt)
Replaced usage of char in many places with std::string (punt)
Started process of replacing UString usage with functions provided through StringUtility instead (punt)
Replaced platform specific fileIO handling in Windows/Linux with cross-platform C++17 standard std::filesystem (punt)
Replaced platform specific time handling by using cross-platform chrono library (punt)
Removed UOX namespace to reduce complexity (punt)
Elimitated template code approach to singletons for more modern c++ constructs, removing dependices in the process (punt)
Removed ODBC support; it hasn't been touched since the initial implementation in 2008, and there is a lack of someone to maintain the code. (punt)
Removed some platform specific files like uoxlinux.h, which is no longer required (punt)
Removed legacy crash protection code, and removed support for cluox (punt)
Removed legacy "support" for Borland compiler (punt)
Removed legacy VC++ 6 Workspace/Project files, VS2005 Solution/Project files, as these are no longer supported (Xuri)
Removed legacy BUILD folder with outdated compilation instructions (Xuri)
Removed old Changelog file (merged into Changelog.txt) (Xuri)
Fixed a pointer bug for items in multis on world load (punt)
Fixed a dictionary related issue that caused segmentation faults on Linux/MacOS (punt)
Fixed an issue with callbacks to JS scripts that caused segmentation faults on Linux/MacOS (punt)
Paths in uox.ini should now load properly on all platforms regardless of whether those paths use slashes or backslashes, and whether or not they end in a slash/backslash. (punt)
Moved to c++17 style of threading, and got rid of threadsafeobject.cpp/h (punt)
Replaced parsing of UOX.INI tags with a system that's more easily maintainable (punt)
Added some new commands to js/commands/custom/misc-cmd.js (Xuri)
cont // Targeted item will be made a container, set to nondecay and movable 2
endfight // Targeted character (and character being fought) will stop fighting
getmulti // Get multiObject for targeted item
finditem // Find item at layer X
movespeed // Set movement speed of target player (0x0 Normal, 0x1 Mounted, 0x2 Slow (walk only), 0x3 Hybrid ("jog"?), 0x4 Frozen)
Added new HTML based documentation in docs folder, and removed many old legacy docs that are either incorporated into this document already or no longer relevant for the current UOX3 version (Xuri)
Co-Authored-By: Charles Kerr <punt1959@users.noreply.github.com>
2020-09-07 18:09:55 +08:00
|
|
|
js_GetSrcNoteCached(JSContext *cx, JSScript *script, jsbytecode *pc)
|
2018-09-08 18:08:48 +08:00
|
|
|
{
|
Numerous changes with focus on feature and stability parity across Windows, Linux and MacOS platforms
Added new Makefile that handles compiling UOX3 and Spidermonkey on both Linux and MacOS (punt)
Added VS solution (SpiderMonkey.sln) and VC++ project files for compiling SpiderMonkey on Windows (Xuri)
Updated SpiderMonkey from v1.6.0 to v1.7.0
Added optimization flag -O2 for release build in CMakeLists.txt in project root (Xuri)
Added StringUtility file with general common string manipulation functions (punt)
Updated RandomNum function to use a "seedless" random number generator from C++11 instead of the old C rand() function. (punt)
Overall code cleanup to remove/replace platform-dependent code (punt)
Replaced potentially unsafe usage of C string stuff like sprintf, vsprintf, vsnprintf, strncat, strcpy and strlen throughout the code with calls to a format() function containing only a single, safe use of vsnprintf, ensuring there's a single place of failure if there's anything to fix and and making it easy to potentially replace this with std::format from C++20 when the time comes. (punt)
Replaced usage of char in many places with std::string (punt)
Started process of replacing UString usage with functions provided through StringUtility instead (punt)
Replaced platform specific fileIO handling in Windows/Linux with cross-platform C++17 standard std::filesystem (punt)
Replaced platform specific time handling by using cross-platform chrono library (punt)
Removed UOX namespace to reduce complexity (punt)
Elimitated template code approach to singletons for more modern c++ constructs, removing dependices in the process (punt)
Removed ODBC support; it hasn't been touched since the initial implementation in 2008, and there is a lack of someone to maintain the code. (punt)
Removed some platform specific files like uoxlinux.h, which is no longer required (punt)
Removed legacy crash protection code, and removed support for cluox (punt)
Removed legacy "support" for Borland compiler (punt)
Removed legacy VC++ 6 Workspace/Project files, VS2005 Solution/Project files, as these are no longer supported (Xuri)
Removed legacy BUILD folder with outdated compilation instructions (Xuri)
Removed old Changelog file (merged into Changelog.txt) (Xuri)
Fixed a pointer bug for items in multis on world load (punt)
Fixed a dictionary related issue that caused segmentation faults on Linux/MacOS (punt)
Fixed an issue with callbacks to JS scripts that caused segmentation faults on Linux/MacOS (punt)
Paths in uox.ini should now load properly on all platforms regardless of whether those paths use slashes or backslashes, and whether or not they end in a slash/backslash. (punt)
Moved to c++17 style of threading, and got rid of threadsafeobject.cpp/h (punt)
Replaced parsing of UOX.INI tags with a system that's more easily maintainable (punt)
Added some new commands to js/commands/custom/misc-cmd.js (Xuri)
cont // Targeted item will be made a container, set to nondecay and movable 2
endfight // Targeted character (and character being fought) will stop fighting
getmulti // Get multiObject for targeted item
finditem // Find item at layer X
movespeed // Set movement speed of target player (0x0 Normal, 0x1 Mounted, 0x2 Slow (walk only), 0x3 Hybrid ("jog"?), 0x4 Frozen)
Added new HTML based documentation in docs folder, and removed many old legacy docs that are either incorporated into this document already or no longer relevant for the current UOX3 version (Xuri)
Co-Authored-By: Charles Kerr <punt1959@users.noreply.github.com>
2020-09-07 18:09:55 +08:00
|
|
|
ptrdiff_t target, offset;
|
|
|
|
|
GSNCacheEntry *entry;
|
|
|
|
|
jssrcnote *sn, *result;
|
|
|
|
|
uintN nsrcnotes;
|
|
|
|
|
|
2018-09-08 18:08:48 +08:00
|
|
|
|
2025-02-05 12:40:54 +10:00
|
|
|
target = pc - script->code;
|
2018-09-08 18:08:48 +08:00
|
|
|
if ((uint32)target >= script->length)
|
|
|
|
|
return NULL;
|
Numerous changes with focus on feature and stability parity across Windows, Linux and MacOS platforms
Added new Makefile that handles compiling UOX3 and Spidermonkey on both Linux and MacOS (punt)
Added VS solution (SpiderMonkey.sln) and VC++ project files for compiling SpiderMonkey on Windows (Xuri)
Updated SpiderMonkey from v1.6.0 to v1.7.0
Added optimization flag -O2 for release build in CMakeLists.txt in project root (Xuri)
Added StringUtility file with general common string manipulation functions (punt)
Updated RandomNum function to use a "seedless" random number generator from C++11 instead of the old C rand() function. (punt)
Overall code cleanup to remove/replace platform-dependent code (punt)
Replaced potentially unsafe usage of C string stuff like sprintf, vsprintf, vsnprintf, strncat, strcpy and strlen throughout the code with calls to a format() function containing only a single, safe use of vsnprintf, ensuring there's a single place of failure if there's anything to fix and and making it easy to potentially replace this with std::format from C++20 when the time comes. (punt)
Replaced usage of char in many places with std::string (punt)
Started process of replacing UString usage with functions provided through StringUtility instead (punt)
Replaced platform specific fileIO handling in Windows/Linux with cross-platform C++17 standard std::filesystem (punt)
Replaced platform specific time handling by using cross-platform chrono library (punt)
Removed UOX namespace to reduce complexity (punt)
Elimitated template code approach to singletons for more modern c++ constructs, removing dependices in the process (punt)
Removed ODBC support; it hasn't been touched since the initial implementation in 2008, and there is a lack of someone to maintain the code. (punt)
Removed some platform specific files like uoxlinux.h, which is no longer required (punt)
Removed legacy crash protection code, and removed support for cluox (punt)
Removed legacy "support" for Borland compiler (punt)
Removed legacy VC++ 6 Workspace/Project files, VS2005 Solution/Project files, as these are no longer supported (Xuri)
Removed legacy BUILD folder with outdated compilation instructions (Xuri)
Removed old Changelog file (merged into Changelog.txt) (Xuri)
Fixed a pointer bug for items in multis on world load (punt)
Fixed a dictionary related issue that caused segmentation faults on Linux/MacOS (punt)
Fixed an issue with callbacks to JS scripts that caused segmentation faults on Linux/MacOS (punt)
Paths in uox.ini should now load properly on all platforms regardless of whether those paths use slashes or backslashes, and whether or not they end in a slash/backslash. (punt)
Moved to c++17 style of threading, and got rid of threadsafeobject.cpp/h (punt)
Replaced parsing of UOX.INI tags with a system that's more easily maintainable (punt)
Added some new commands to js/commands/custom/misc-cmd.js (Xuri)
cont // Targeted item will be made a container, set to nondecay and movable 2
endfight // Targeted character (and character being fought) will stop fighting
getmulti // Get multiObject for targeted item
finditem // Find item at layer X
movespeed // Set movement speed of target player (0x0 Normal, 0x1 Mounted, 0x2 Slow (walk only), 0x3 Hybrid ("jog"?), 0x4 Frozen)
Added new HTML based documentation in docs folder, and removed many old legacy docs that are either incorporated into this document already or no longer relevant for the current UOX3 version (Xuri)
Co-Authored-By: Charles Kerr <punt1959@users.noreply.github.com>
2020-09-07 18:09:55 +08:00
|
|
|
|
2023-07-12 13:27:26 +10:00
|
|
|
if (JS_GSN_CACHE(cx).code == script->code) {
|
Numerous changes with focus on feature and stability parity across Windows, Linux and MacOS platforms
Added new Makefile that handles compiling UOX3 and Spidermonkey on both Linux and MacOS (punt)
Added VS solution (SpiderMonkey.sln) and VC++ project files for compiling SpiderMonkey on Windows (Xuri)
Updated SpiderMonkey from v1.6.0 to v1.7.0
Added optimization flag -O2 for release build in CMakeLists.txt in project root (Xuri)
Added StringUtility file with general common string manipulation functions (punt)
Updated RandomNum function to use a "seedless" random number generator from C++11 instead of the old C rand() function. (punt)
Overall code cleanup to remove/replace platform-dependent code (punt)
Replaced potentially unsafe usage of C string stuff like sprintf, vsprintf, vsnprintf, strncat, strcpy and strlen throughout the code with calls to a format() function containing only a single, safe use of vsnprintf, ensuring there's a single place of failure if there's anything to fix and and making it easy to potentially replace this with std::format from C++20 when the time comes. (punt)
Replaced usage of char in many places with std::string (punt)
Started process of replacing UString usage with functions provided through StringUtility instead (punt)
Replaced platform specific fileIO handling in Windows/Linux with cross-platform C++17 standard std::filesystem (punt)
Replaced platform specific time handling by using cross-platform chrono library (punt)
Removed UOX namespace to reduce complexity (punt)
Elimitated template code approach to singletons for more modern c++ constructs, removing dependices in the process (punt)
Removed ODBC support; it hasn't been touched since the initial implementation in 2008, and there is a lack of someone to maintain the code. (punt)
Removed some platform specific files like uoxlinux.h, which is no longer required (punt)
Removed legacy crash protection code, and removed support for cluox (punt)
Removed legacy "support" for Borland compiler (punt)
Removed legacy VC++ 6 Workspace/Project files, VS2005 Solution/Project files, as these are no longer supported (Xuri)
Removed legacy BUILD folder with outdated compilation instructions (Xuri)
Removed old Changelog file (merged into Changelog.txt) (Xuri)
Fixed a pointer bug for items in multis on world load (punt)
Fixed a dictionary related issue that caused segmentation faults on Linux/MacOS (punt)
Fixed an issue with callbacks to JS scripts that caused segmentation faults on Linux/MacOS (punt)
Paths in uox.ini should now load properly on all platforms regardless of whether those paths use slashes or backslashes, and whether or not they end in a slash/backslash. (punt)
Moved to c++17 style of threading, and got rid of threadsafeobject.cpp/h (punt)
Replaced parsing of UOX.INI tags with a system that's more easily maintainable (punt)
Added some new commands to js/commands/custom/misc-cmd.js (Xuri)
cont // Targeted item will be made a container, set to nondecay and movable 2
endfight // Targeted character (and character being fought) will stop fighting
getmulti // Get multiObject for targeted item
finditem // Find item at layer X
movespeed // Set movement speed of target player (0x0 Normal, 0x1 Mounted, 0x2 Slow (walk only), 0x3 Hybrid ("jog"?), 0x4 Frozen)
Added new HTML based documentation in docs folder, and removed many old legacy docs that are either incorporated into this document already or no longer relevant for the current UOX3 version (Xuri)
Co-Authored-By: Charles Kerr <punt1959@users.noreply.github.com>
2020-09-07 18:09:55 +08:00
|
|
|
JS_METER_GSN_CACHE(cx, hits);
|
|
|
|
|
entry = (GSNCacheEntry *)
|
|
|
|
|
JS_DHashTableOperate(&JS_GSN_CACHE(cx).table, pc,
|
|
|
|
|
JS_DHASH_LOOKUP);
|
|
|
|
|
return entry->sn;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
JS_METER_GSN_CACHE(cx, misses);
|
2018-09-08 18:08:48 +08:00
|
|
|
offset = 0;
|
2025-02-05 12:40:54 +10:00
|
|
|
for (sn = script->notes(); ; sn = SN_NEXT(sn)) {
|
Numerous changes with focus on feature and stability parity across Windows, Linux and MacOS platforms
Added new Makefile that handles compiling UOX3 and Spidermonkey on both Linux and MacOS (punt)
Added VS solution (SpiderMonkey.sln) and VC++ project files for compiling SpiderMonkey on Windows (Xuri)
Updated SpiderMonkey from v1.6.0 to v1.7.0
Added optimization flag -O2 for release build in CMakeLists.txt in project root (Xuri)
Added StringUtility file with general common string manipulation functions (punt)
Updated RandomNum function to use a "seedless" random number generator from C++11 instead of the old C rand() function. (punt)
Overall code cleanup to remove/replace platform-dependent code (punt)
Replaced potentially unsafe usage of C string stuff like sprintf, vsprintf, vsnprintf, strncat, strcpy and strlen throughout the code with calls to a format() function containing only a single, safe use of vsnprintf, ensuring there's a single place of failure if there's anything to fix and and making it easy to potentially replace this with std::format from C++20 when the time comes. (punt)
Replaced usage of char in many places with std::string (punt)
Started process of replacing UString usage with functions provided through StringUtility instead (punt)
Replaced platform specific fileIO handling in Windows/Linux with cross-platform C++17 standard std::filesystem (punt)
Replaced platform specific time handling by using cross-platform chrono library (punt)
Removed UOX namespace to reduce complexity (punt)
Elimitated template code approach to singletons for more modern c++ constructs, removing dependices in the process (punt)
Removed ODBC support; it hasn't been touched since the initial implementation in 2008, and there is a lack of someone to maintain the code. (punt)
Removed some platform specific files like uoxlinux.h, which is no longer required (punt)
Removed legacy crash protection code, and removed support for cluox (punt)
Removed legacy "support" for Borland compiler (punt)
Removed legacy VC++ 6 Workspace/Project files, VS2005 Solution/Project files, as these are no longer supported (Xuri)
Removed legacy BUILD folder with outdated compilation instructions (Xuri)
Removed old Changelog file (merged into Changelog.txt) (Xuri)
Fixed a pointer bug for items in multis on world load (punt)
Fixed a dictionary related issue that caused segmentation faults on Linux/MacOS (punt)
Fixed an issue with callbacks to JS scripts that caused segmentation faults on Linux/MacOS (punt)
Paths in uox.ini should now load properly on all platforms regardless of whether those paths use slashes or backslashes, and whether or not they end in a slash/backslash. (punt)
Moved to c++17 style of threading, and got rid of threadsafeobject.cpp/h (punt)
Replaced parsing of UOX.INI tags with a system that's more easily maintainable (punt)
Added some new commands to js/commands/custom/misc-cmd.js (Xuri)
cont // Targeted item will be made a container, set to nondecay and movable 2
endfight // Targeted character (and character being fought) will stop fighting
getmulti // Get multiObject for targeted item
finditem // Find item at layer X
movespeed // Set movement speed of target player (0x0 Normal, 0x1 Mounted, 0x2 Slow (walk only), 0x3 Hybrid ("jog"?), 0x4 Frozen)
Added new HTML based documentation in docs folder, and removed many old legacy docs that are either incorporated into this document already or no longer relevant for the current UOX3 version (Xuri)
Co-Authored-By: Charles Kerr <punt1959@users.noreply.github.com>
2020-09-07 18:09:55 +08:00
|
|
|
if (SN_IS_TERMINATOR(sn)) {
|
|
|
|
|
result = NULL;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2018-09-08 18:08:48 +08:00
|
|
|
offset += SN_DELTA(sn);
|
Numerous changes with focus on feature and stability parity across Windows, Linux and MacOS platforms
Added new Makefile that handles compiling UOX3 and Spidermonkey on both Linux and MacOS (punt)
Added VS solution (SpiderMonkey.sln) and VC++ project files for compiling SpiderMonkey on Windows (Xuri)
Updated SpiderMonkey from v1.6.0 to v1.7.0
Added optimization flag -O2 for release build in CMakeLists.txt in project root (Xuri)
Added StringUtility file with general common string manipulation functions (punt)
Updated RandomNum function to use a "seedless" random number generator from C++11 instead of the old C rand() function. (punt)
Overall code cleanup to remove/replace platform-dependent code (punt)
Replaced potentially unsafe usage of C string stuff like sprintf, vsprintf, vsnprintf, strncat, strcpy and strlen throughout the code with calls to a format() function containing only a single, safe use of vsnprintf, ensuring there's a single place of failure if there's anything to fix and and making it easy to potentially replace this with std::format from C++20 when the time comes. (punt)
Replaced usage of char in many places with std::string (punt)
Started process of replacing UString usage with functions provided through StringUtility instead (punt)
Replaced platform specific fileIO handling in Windows/Linux with cross-platform C++17 standard std::filesystem (punt)
Replaced platform specific time handling by using cross-platform chrono library (punt)
Removed UOX namespace to reduce complexity (punt)
Elimitated template code approach to singletons for more modern c++ constructs, removing dependices in the process (punt)
Removed ODBC support; it hasn't been touched since the initial implementation in 2008, and there is a lack of someone to maintain the code. (punt)
Removed some platform specific files like uoxlinux.h, which is no longer required (punt)
Removed legacy crash protection code, and removed support for cluox (punt)
Removed legacy "support" for Borland compiler (punt)
Removed legacy VC++ 6 Workspace/Project files, VS2005 Solution/Project files, as these are no longer supported (Xuri)
Removed legacy BUILD folder with outdated compilation instructions (Xuri)
Removed old Changelog file (merged into Changelog.txt) (Xuri)
Fixed a pointer bug for items in multis on world load (punt)
Fixed a dictionary related issue that caused segmentation faults on Linux/MacOS (punt)
Fixed an issue with callbacks to JS scripts that caused segmentation faults on Linux/MacOS (punt)
Paths in uox.ini should now load properly on all platforms regardless of whether those paths use slashes or backslashes, and whether or not they end in a slash/backslash. (punt)
Moved to c++17 style of threading, and got rid of threadsafeobject.cpp/h (punt)
Replaced parsing of UOX.INI tags with a system that's more easily maintainable (punt)
Added some new commands to js/commands/custom/misc-cmd.js (Xuri)
cont // Targeted item will be made a container, set to nondecay and movable 2
endfight // Targeted character (and character being fought) will stop fighting
getmulti // Get multiObject for targeted item
finditem // Find item at layer X
movespeed // Set movement speed of target player (0x0 Normal, 0x1 Mounted, 0x2 Slow (walk only), 0x3 Hybrid ("jog"?), 0x4 Frozen)
Added new HTML based documentation in docs folder, and removed many old legacy docs that are either incorporated into this document already or no longer relevant for the current UOX3 version (Xuri)
Co-Authored-By: Charles Kerr <punt1959@users.noreply.github.com>
2020-09-07 18:09:55 +08:00
|
|
|
if (offset == target && SN_IS_GETTABLE(sn)) {
|
|
|
|
|
result = sn;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2018-09-08 18:08:48 +08:00
|
|
|
}
|
Numerous changes with focus on feature and stability parity across Windows, Linux and MacOS platforms
Added new Makefile that handles compiling UOX3 and Spidermonkey on both Linux and MacOS (punt)
Added VS solution (SpiderMonkey.sln) and VC++ project files for compiling SpiderMonkey on Windows (Xuri)
Updated SpiderMonkey from v1.6.0 to v1.7.0
Added optimization flag -O2 for release build in CMakeLists.txt in project root (Xuri)
Added StringUtility file with general common string manipulation functions (punt)
Updated RandomNum function to use a "seedless" random number generator from C++11 instead of the old C rand() function. (punt)
Overall code cleanup to remove/replace platform-dependent code (punt)
Replaced potentially unsafe usage of C string stuff like sprintf, vsprintf, vsnprintf, strncat, strcpy and strlen throughout the code with calls to a format() function containing only a single, safe use of vsnprintf, ensuring there's a single place of failure if there's anything to fix and and making it easy to potentially replace this with std::format from C++20 when the time comes. (punt)
Replaced usage of char in many places with std::string (punt)
Started process of replacing UString usage with functions provided through StringUtility instead (punt)
Replaced platform specific fileIO handling in Windows/Linux with cross-platform C++17 standard std::filesystem (punt)
Replaced platform specific time handling by using cross-platform chrono library (punt)
Removed UOX namespace to reduce complexity (punt)
Elimitated template code approach to singletons for more modern c++ constructs, removing dependices in the process (punt)
Removed ODBC support; it hasn't been touched since the initial implementation in 2008, and there is a lack of someone to maintain the code. (punt)
Removed some platform specific files like uoxlinux.h, which is no longer required (punt)
Removed legacy crash protection code, and removed support for cluox (punt)
Removed legacy "support" for Borland compiler (punt)
Removed legacy VC++ 6 Workspace/Project files, VS2005 Solution/Project files, as these are no longer supported (Xuri)
Removed legacy BUILD folder with outdated compilation instructions (Xuri)
Removed old Changelog file (merged into Changelog.txt) (Xuri)
Fixed a pointer bug for items in multis on world load (punt)
Fixed a dictionary related issue that caused segmentation faults on Linux/MacOS (punt)
Fixed an issue with callbacks to JS scripts that caused segmentation faults on Linux/MacOS (punt)
Paths in uox.ini should now load properly on all platforms regardless of whether those paths use slashes or backslashes, and whether or not they end in a slash/backslash. (punt)
Moved to c++17 style of threading, and got rid of threadsafeobject.cpp/h (punt)
Replaced parsing of UOX.INI tags with a system that's more easily maintainable (punt)
Added some new commands to js/commands/custom/misc-cmd.js (Xuri)
cont // Targeted item will be made a container, set to nondecay and movable 2
endfight // Targeted character (and character being fought) will stop fighting
getmulti // Get multiObject for targeted item
finditem // Find item at layer X
movespeed // Set movement speed of target player (0x0 Normal, 0x1 Mounted, 0x2 Slow (walk only), 0x3 Hybrid ("jog"?), 0x4 Frozen)
Added new HTML based documentation in docs folder, and removed many old legacy docs that are either incorporated into this document already or no longer relevant for the current UOX3 version (Xuri)
Co-Authored-By: Charles Kerr <punt1959@users.noreply.github.com>
2020-09-07 18:09:55 +08:00
|
|
|
|
2023-07-12 13:27:26 +10:00
|
|
|
if (JS_GSN_CACHE(cx).code != script->code &&
|
Numerous changes with focus on feature and stability parity across Windows, Linux and MacOS platforms
Added new Makefile that handles compiling UOX3 and Spidermonkey on both Linux and MacOS (punt)
Added VS solution (SpiderMonkey.sln) and VC++ project files for compiling SpiderMonkey on Windows (Xuri)
Updated SpiderMonkey from v1.6.0 to v1.7.0
Added optimization flag -O2 for release build in CMakeLists.txt in project root (Xuri)
Added StringUtility file with general common string manipulation functions (punt)
Updated RandomNum function to use a "seedless" random number generator from C++11 instead of the old C rand() function. (punt)
Overall code cleanup to remove/replace platform-dependent code (punt)
Replaced potentially unsafe usage of C string stuff like sprintf, vsprintf, vsnprintf, strncat, strcpy and strlen throughout the code with calls to a format() function containing only a single, safe use of vsnprintf, ensuring there's a single place of failure if there's anything to fix and and making it easy to potentially replace this with std::format from C++20 when the time comes. (punt)
Replaced usage of char in many places with std::string (punt)
Started process of replacing UString usage with functions provided through StringUtility instead (punt)
Replaced platform specific fileIO handling in Windows/Linux with cross-platform C++17 standard std::filesystem (punt)
Replaced platform specific time handling by using cross-platform chrono library (punt)
Removed UOX namespace to reduce complexity (punt)
Elimitated template code approach to singletons for more modern c++ constructs, removing dependices in the process (punt)
Removed ODBC support; it hasn't been touched since the initial implementation in 2008, and there is a lack of someone to maintain the code. (punt)
Removed some platform specific files like uoxlinux.h, which is no longer required (punt)
Removed legacy crash protection code, and removed support for cluox (punt)
Removed legacy "support" for Borland compiler (punt)
Removed legacy VC++ 6 Workspace/Project files, VS2005 Solution/Project files, as these are no longer supported (Xuri)
Removed legacy BUILD folder with outdated compilation instructions (Xuri)
Removed old Changelog file (merged into Changelog.txt) (Xuri)
Fixed a pointer bug for items in multis on world load (punt)
Fixed a dictionary related issue that caused segmentation faults on Linux/MacOS (punt)
Fixed an issue with callbacks to JS scripts that caused segmentation faults on Linux/MacOS (punt)
Paths in uox.ini should now load properly on all platforms regardless of whether those paths use slashes or backslashes, and whether or not they end in a slash/backslash. (punt)
Moved to c++17 style of threading, and got rid of threadsafeobject.cpp/h (punt)
Replaced parsing of UOX.INI tags with a system that's more easily maintainable (punt)
Added some new commands to js/commands/custom/misc-cmd.js (Xuri)
cont // Targeted item will be made a container, set to nondecay and movable 2
endfight // Targeted character (and character being fought) will stop fighting
getmulti // Get multiObject for targeted item
finditem // Find item at layer X
movespeed // Set movement speed of target player (0x0 Normal, 0x1 Mounted, 0x2 Slow (walk only), 0x3 Hybrid ("jog"?), 0x4 Frozen)
Added new HTML based documentation in docs folder, and removed many old legacy docs that are either incorporated into this document already or no longer relevant for the current UOX3 version (Xuri)
Co-Authored-By: Charles Kerr <punt1959@users.noreply.github.com>
2020-09-07 18:09:55 +08:00
|
|
|
script->length >= GSN_CACHE_THRESHOLD) {
|
2025-02-05 12:40:54 +10:00
|
|
|
JS_PURGE_GSN_CACHE(cx);
|
Numerous changes with focus on feature and stability parity across Windows, Linux and MacOS platforms
Added new Makefile that handles compiling UOX3 and Spidermonkey on both Linux and MacOS (punt)
Added VS solution (SpiderMonkey.sln) and VC++ project files for compiling SpiderMonkey on Windows (Xuri)
Updated SpiderMonkey from v1.6.0 to v1.7.0
Added optimization flag -O2 for release build in CMakeLists.txt in project root (Xuri)
Added StringUtility file with general common string manipulation functions (punt)
Updated RandomNum function to use a "seedless" random number generator from C++11 instead of the old C rand() function. (punt)
Overall code cleanup to remove/replace platform-dependent code (punt)
Replaced potentially unsafe usage of C string stuff like sprintf, vsprintf, vsnprintf, strncat, strcpy and strlen throughout the code with calls to a format() function containing only a single, safe use of vsnprintf, ensuring there's a single place of failure if there's anything to fix and and making it easy to potentially replace this with std::format from C++20 when the time comes. (punt)
Replaced usage of char in many places with std::string (punt)
Started process of replacing UString usage with functions provided through StringUtility instead (punt)
Replaced platform specific fileIO handling in Windows/Linux with cross-platform C++17 standard std::filesystem (punt)
Replaced platform specific time handling by using cross-platform chrono library (punt)
Removed UOX namespace to reduce complexity (punt)
Elimitated template code approach to singletons for more modern c++ constructs, removing dependices in the process (punt)
Removed ODBC support; it hasn't been touched since the initial implementation in 2008, and there is a lack of someone to maintain the code. (punt)
Removed some platform specific files like uoxlinux.h, which is no longer required (punt)
Removed legacy crash protection code, and removed support for cluox (punt)
Removed legacy "support" for Borland compiler (punt)
Removed legacy VC++ 6 Workspace/Project files, VS2005 Solution/Project files, as these are no longer supported (Xuri)
Removed legacy BUILD folder with outdated compilation instructions (Xuri)
Removed old Changelog file (merged into Changelog.txt) (Xuri)
Fixed a pointer bug for items in multis on world load (punt)
Fixed a dictionary related issue that caused segmentation faults on Linux/MacOS (punt)
Fixed an issue with callbacks to JS scripts that caused segmentation faults on Linux/MacOS (punt)
Paths in uox.ini should now load properly on all platforms regardless of whether those paths use slashes or backslashes, and whether or not they end in a slash/backslash. (punt)
Moved to c++17 style of threading, and got rid of threadsafeobject.cpp/h (punt)
Replaced parsing of UOX.INI tags with a system that's more easily maintainable (punt)
Added some new commands to js/commands/custom/misc-cmd.js (Xuri)
cont // Targeted item will be made a container, set to nondecay and movable 2
endfight // Targeted character (and character being fought) will stop fighting
getmulti // Get multiObject for targeted item
finditem // Find item at layer X
movespeed // Set movement speed of target player (0x0 Normal, 0x1 Mounted, 0x2 Slow (walk only), 0x3 Hybrid ("jog"?), 0x4 Frozen)
Added new HTML based documentation in docs folder, and removed many old legacy docs that are either incorporated into this document already or no longer relevant for the current UOX3 version (Xuri)
Co-Authored-By: Charles Kerr <punt1959@users.noreply.github.com>
2020-09-07 18:09:55 +08:00
|
|
|
nsrcnotes = 0;
|
2025-02-05 12:40:54 +10:00
|
|
|
for (sn = script->notes(); !SN_IS_TERMINATOR(sn);
|
Numerous changes with focus on feature and stability parity across Windows, Linux and MacOS platforms
Added new Makefile that handles compiling UOX3 and Spidermonkey on both Linux and MacOS (punt)
Added VS solution (SpiderMonkey.sln) and VC++ project files for compiling SpiderMonkey on Windows (Xuri)
Updated SpiderMonkey from v1.6.0 to v1.7.0
Added optimization flag -O2 for release build in CMakeLists.txt in project root (Xuri)
Added StringUtility file with general common string manipulation functions (punt)
Updated RandomNum function to use a "seedless" random number generator from C++11 instead of the old C rand() function. (punt)
Overall code cleanup to remove/replace platform-dependent code (punt)
Replaced potentially unsafe usage of C string stuff like sprintf, vsprintf, vsnprintf, strncat, strcpy and strlen throughout the code with calls to a format() function containing only a single, safe use of vsnprintf, ensuring there's a single place of failure if there's anything to fix and and making it easy to potentially replace this with std::format from C++20 when the time comes. (punt)
Replaced usage of char in many places with std::string (punt)
Started process of replacing UString usage with functions provided through StringUtility instead (punt)
Replaced platform specific fileIO handling in Windows/Linux with cross-platform C++17 standard std::filesystem (punt)
Replaced platform specific time handling by using cross-platform chrono library (punt)
Removed UOX namespace to reduce complexity (punt)
Elimitated template code approach to singletons for more modern c++ constructs, removing dependices in the process (punt)
Removed ODBC support; it hasn't been touched since the initial implementation in 2008, and there is a lack of someone to maintain the code. (punt)
Removed some platform specific files like uoxlinux.h, which is no longer required (punt)
Removed legacy crash protection code, and removed support for cluox (punt)
Removed legacy "support" for Borland compiler (punt)
Removed legacy VC++ 6 Workspace/Project files, VS2005 Solution/Project files, as these are no longer supported (Xuri)
Removed legacy BUILD folder with outdated compilation instructions (Xuri)
Removed old Changelog file (merged into Changelog.txt) (Xuri)
Fixed a pointer bug for items in multis on world load (punt)
Fixed a dictionary related issue that caused segmentation faults on Linux/MacOS (punt)
Fixed an issue with callbacks to JS scripts that caused segmentation faults on Linux/MacOS (punt)
Paths in uox.ini should now load properly on all platforms regardless of whether those paths use slashes or backslashes, and whether or not they end in a slash/backslash. (punt)
Moved to c++17 style of threading, and got rid of threadsafeobject.cpp/h (punt)
Replaced parsing of UOX.INI tags with a system that's more easily maintainable (punt)
Added some new commands to js/commands/custom/misc-cmd.js (Xuri)
cont // Targeted item will be made a container, set to nondecay and movable 2
endfight // Targeted character (and character being fought) will stop fighting
getmulti // Get multiObject for targeted item
finditem // Find item at layer X
movespeed // Set movement speed of target player (0x0 Normal, 0x1 Mounted, 0x2 Slow (walk only), 0x3 Hybrid ("jog"?), 0x4 Frozen)
Added new HTML based documentation in docs folder, and removed many old legacy docs that are either incorporated into this document already or no longer relevant for the current UOX3 version (Xuri)
Co-Authored-By: Charles Kerr <punt1959@users.noreply.github.com>
2020-09-07 18:09:55 +08:00
|
|
|
sn = SN_NEXT(sn)) {
|
|
|
|
|
if (SN_IS_GETTABLE(sn))
|
|
|
|
|
++nsrcnotes;
|
|
|
|
|
}
|
|
|
|
|
if (!JS_DHashTableInit(&JS_GSN_CACHE(cx).table, JS_DHashGetStubOps(),
|
2023-07-12 13:27:26 +10:00
|
|
|
NULL, sizeof(GSNCacheEntry),
|
|
|
|
|
JS_DHASH_DEFAULT_CAPACITY(nsrcnotes))) {
|
Numerous changes with focus on feature and stability parity across Windows, Linux and MacOS platforms
Added new Makefile that handles compiling UOX3 and Spidermonkey on both Linux and MacOS (punt)
Added VS solution (SpiderMonkey.sln) and VC++ project files for compiling SpiderMonkey on Windows (Xuri)
Updated SpiderMonkey from v1.6.0 to v1.7.0
Added optimization flag -O2 for release build in CMakeLists.txt in project root (Xuri)
Added StringUtility file with general common string manipulation functions (punt)
Updated RandomNum function to use a "seedless" random number generator from C++11 instead of the old C rand() function. (punt)
Overall code cleanup to remove/replace platform-dependent code (punt)
Replaced potentially unsafe usage of C string stuff like sprintf, vsprintf, vsnprintf, strncat, strcpy and strlen throughout the code with calls to a format() function containing only a single, safe use of vsnprintf, ensuring there's a single place of failure if there's anything to fix and and making it easy to potentially replace this with std::format from C++20 when the time comes. (punt)
Replaced usage of char in many places with std::string (punt)
Started process of replacing UString usage with functions provided through StringUtility instead (punt)
Replaced platform specific fileIO handling in Windows/Linux with cross-platform C++17 standard std::filesystem (punt)
Replaced platform specific time handling by using cross-platform chrono library (punt)
Removed UOX namespace to reduce complexity (punt)
Elimitated template code approach to singletons for more modern c++ constructs, removing dependices in the process (punt)
Removed ODBC support; it hasn't been touched since the initial implementation in 2008, and there is a lack of someone to maintain the code. (punt)
Removed some platform specific files like uoxlinux.h, which is no longer required (punt)
Removed legacy crash protection code, and removed support for cluox (punt)
Removed legacy "support" for Borland compiler (punt)
Removed legacy VC++ 6 Workspace/Project files, VS2005 Solution/Project files, as these are no longer supported (Xuri)
Removed legacy BUILD folder with outdated compilation instructions (Xuri)
Removed old Changelog file (merged into Changelog.txt) (Xuri)
Fixed a pointer bug for items in multis on world load (punt)
Fixed a dictionary related issue that caused segmentation faults on Linux/MacOS (punt)
Fixed an issue with callbacks to JS scripts that caused segmentation faults on Linux/MacOS (punt)
Paths in uox.ini should now load properly on all platforms regardless of whether those paths use slashes or backslashes, and whether or not they end in a slash/backslash. (punt)
Moved to c++17 style of threading, and got rid of threadsafeobject.cpp/h (punt)
Replaced parsing of UOX.INI tags with a system that's more easily maintainable (punt)
Added some new commands to js/commands/custom/misc-cmd.js (Xuri)
cont // Targeted item will be made a container, set to nondecay and movable 2
endfight // Targeted character (and character being fought) will stop fighting
getmulti // Get multiObject for targeted item
finditem // Find item at layer X
movespeed // Set movement speed of target player (0x0 Normal, 0x1 Mounted, 0x2 Slow (walk only), 0x3 Hybrid ("jog"?), 0x4 Frozen)
Added new HTML based documentation in docs folder, and removed many old legacy docs that are either incorporated into this document already or no longer relevant for the current UOX3 version (Xuri)
Co-Authored-By: Charles Kerr <punt1959@users.noreply.github.com>
2020-09-07 18:09:55 +08:00
|
|
|
JS_GSN_CACHE(cx).table.ops = NULL;
|
|
|
|
|
} else {
|
|
|
|
|
pc = script->code;
|
2025-02-05 12:40:54 +10:00
|
|
|
for (sn = script->notes(); !SN_IS_TERMINATOR(sn);
|
Numerous changes with focus on feature and stability parity across Windows, Linux and MacOS platforms
Added new Makefile that handles compiling UOX3 and Spidermonkey on both Linux and MacOS (punt)
Added VS solution (SpiderMonkey.sln) and VC++ project files for compiling SpiderMonkey on Windows (Xuri)
Updated SpiderMonkey from v1.6.0 to v1.7.0
Added optimization flag -O2 for release build in CMakeLists.txt in project root (Xuri)
Added StringUtility file with general common string manipulation functions (punt)
Updated RandomNum function to use a "seedless" random number generator from C++11 instead of the old C rand() function. (punt)
Overall code cleanup to remove/replace platform-dependent code (punt)
Replaced potentially unsafe usage of C string stuff like sprintf, vsprintf, vsnprintf, strncat, strcpy and strlen throughout the code with calls to a format() function containing only a single, safe use of vsnprintf, ensuring there's a single place of failure if there's anything to fix and and making it easy to potentially replace this with std::format from C++20 when the time comes. (punt)
Replaced usage of char in many places with std::string (punt)
Started process of replacing UString usage with functions provided through StringUtility instead (punt)
Replaced platform specific fileIO handling in Windows/Linux with cross-platform C++17 standard std::filesystem (punt)
Replaced platform specific time handling by using cross-platform chrono library (punt)
Removed UOX namespace to reduce complexity (punt)
Elimitated template code approach to singletons for more modern c++ constructs, removing dependices in the process (punt)
Removed ODBC support; it hasn't been touched since the initial implementation in 2008, and there is a lack of someone to maintain the code. (punt)
Removed some platform specific files like uoxlinux.h, which is no longer required (punt)
Removed legacy crash protection code, and removed support for cluox (punt)
Removed legacy "support" for Borland compiler (punt)
Removed legacy VC++ 6 Workspace/Project files, VS2005 Solution/Project files, as these are no longer supported (Xuri)
Removed legacy BUILD folder with outdated compilation instructions (Xuri)
Removed old Changelog file (merged into Changelog.txt) (Xuri)
Fixed a pointer bug for items in multis on world load (punt)
Fixed a dictionary related issue that caused segmentation faults on Linux/MacOS (punt)
Fixed an issue with callbacks to JS scripts that caused segmentation faults on Linux/MacOS (punt)
Paths in uox.ini should now load properly on all platforms regardless of whether those paths use slashes or backslashes, and whether or not they end in a slash/backslash. (punt)
Moved to c++17 style of threading, and got rid of threadsafeobject.cpp/h (punt)
Replaced parsing of UOX.INI tags with a system that's more easily maintainable (punt)
Added some new commands to js/commands/custom/misc-cmd.js (Xuri)
cont // Targeted item will be made a container, set to nondecay and movable 2
endfight // Targeted character (and character being fought) will stop fighting
getmulti // Get multiObject for targeted item
finditem // Find item at layer X
movespeed // Set movement speed of target player (0x0 Normal, 0x1 Mounted, 0x2 Slow (walk only), 0x3 Hybrid ("jog"?), 0x4 Frozen)
Added new HTML based documentation in docs folder, and removed many old legacy docs that are either incorporated into this document already or no longer relevant for the current UOX3 version (Xuri)
Co-Authored-By: Charles Kerr <punt1959@users.noreply.github.com>
2020-09-07 18:09:55 +08:00
|
|
|
sn = SN_NEXT(sn)) {
|
|
|
|
|
pc += SN_DELTA(sn);
|
|
|
|
|
if (SN_IS_GETTABLE(sn)) {
|
|
|
|
|
entry = (GSNCacheEntry *)
|
|
|
|
|
JS_DHashTableOperate(&JS_GSN_CACHE(cx).table, pc,
|
|
|
|
|
JS_DHASH_ADD);
|
|
|
|
|
entry->pc = pc;
|
|
|
|
|
entry->sn = sn;
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-07-12 13:27:26 +10:00
|
|
|
JS_GSN_CACHE(cx).code = script->code;
|
Numerous changes with focus on feature and stability parity across Windows, Linux and MacOS platforms
Added new Makefile that handles compiling UOX3 and Spidermonkey on both Linux and MacOS (punt)
Added VS solution (SpiderMonkey.sln) and VC++ project files for compiling SpiderMonkey on Windows (Xuri)
Updated SpiderMonkey from v1.6.0 to v1.7.0
Added optimization flag -O2 for release build in CMakeLists.txt in project root (Xuri)
Added StringUtility file with general common string manipulation functions (punt)
Updated RandomNum function to use a "seedless" random number generator from C++11 instead of the old C rand() function. (punt)
Overall code cleanup to remove/replace platform-dependent code (punt)
Replaced potentially unsafe usage of C string stuff like sprintf, vsprintf, vsnprintf, strncat, strcpy and strlen throughout the code with calls to a format() function containing only a single, safe use of vsnprintf, ensuring there's a single place of failure if there's anything to fix and and making it easy to potentially replace this with std::format from C++20 when the time comes. (punt)
Replaced usage of char in many places with std::string (punt)
Started process of replacing UString usage with functions provided through StringUtility instead (punt)
Replaced platform specific fileIO handling in Windows/Linux with cross-platform C++17 standard std::filesystem (punt)
Replaced platform specific time handling by using cross-platform chrono library (punt)
Removed UOX namespace to reduce complexity (punt)
Elimitated template code approach to singletons for more modern c++ constructs, removing dependices in the process (punt)
Removed ODBC support; it hasn't been touched since the initial implementation in 2008, and there is a lack of someone to maintain the code. (punt)
Removed some platform specific files like uoxlinux.h, which is no longer required (punt)
Removed legacy crash protection code, and removed support for cluox (punt)
Removed legacy "support" for Borland compiler (punt)
Removed legacy VC++ 6 Workspace/Project files, VS2005 Solution/Project files, as these are no longer supported (Xuri)
Removed legacy BUILD folder with outdated compilation instructions (Xuri)
Removed old Changelog file (merged into Changelog.txt) (Xuri)
Fixed a pointer bug for items in multis on world load (punt)
Fixed a dictionary related issue that caused segmentation faults on Linux/MacOS (punt)
Fixed an issue with callbacks to JS scripts that caused segmentation faults on Linux/MacOS (punt)
Paths in uox.ini should now load properly on all platforms regardless of whether those paths use slashes or backslashes, and whether or not they end in a slash/backslash. (punt)
Moved to c++17 style of threading, and got rid of threadsafeobject.cpp/h (punt)
Replaced parsing of UOX.INI tags with a system that's more easily maintainable (punt)
Added some new commands to js/commands/custom/misc-cmd.js (Xuri)
cont // Targeted item will be made a container, set to nondecay and movable 2
endfight // Targeted character (and character being fought) will stop fighting
getmulti // Get multiObject for targeted item
finditem // Find item at layer X
movespeed // Set movement speed of target player (0x0 Normal, 0x1 Mounted, 0x2 Slow (walk only), 0x3 Hybrid ("jog"?), 0x4 Frozen)
Added new HTML based documentation in docs folder, and removed many old legacy docs that are either incorporated into this document already or no longer relevant for the current UOX3 version (Xuri)
Co-Authored-By: Charles Kerr <punt1959@users.noreply.github.com>
2020-09-07 18:09:55 +08:00
|
|
|
JS_METER_GSN_CACHE(cx, fills);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
2018-09-08 18:08:48 +08:00
|
|
|
}
|
|
|
|
|
|
2025-02-05 12:40:54 +10:00
|
|
|
uintN
|
|
|
|
|
js_FramePCToLineNumber(JSContext *cx, JSStackFrame *fp)
|
|
|
|
|
{
|
2025-03-19 21:25:58 +10:00
|
|
|
return js_PCToLineNumber(cx, fp->script(),
|
|
|
|
|
fp->hasImacropc() ? fp->imacropc() : fp->pc(cx));
|
2025-02-05 12:40:54 +10:00
|
|
|
}
|
|
|
|
|
|
2018-09-08 18:08:48 +08:00
|
|
|
uintN
|
|
|
|
|
js_PCToLineNumber(JSContext *cx, JSScript *script, jsbytecode *pc)
|
|
|
|
|
{
|
2025-02-05 12:40:54 +10:00
|
|
|
JSOp op;
|
2018-09-08 18:08:48 +08:00
|
|
|
JSFunction *fun;
|
|
|
|
|
uintN lineno;
|
|
|
|
|
ptrdiff_t offset, target;
|
|
|
|
|
jssrcnote *sn;
|
|
|
|
|
JSSrcNoteType type;
|
|
|
|
|
|
Numerous changes with focus on feature and stability parity across Windows, Linux and MacOS platforms
Added new Makefile that handles compiling UOX3 and Spidermonkey on both Linux and MacOS (punt)
Added VS solution (SpiderMonkey.sln) and VC++ project files for compiling SpiderMonkey on Windows (Xuri)
Updated SpiderMonkey from v1.6.0 to v1.7.0
Added optimization flag -O2 for release build in CMakeLists.txt in project root (Xuri)
Added StringUtility file with general common string manipulation functions (punt)
Updated RandomNum function to use a "seedless" random number generator from C++11 instead of the old C rand() function. (punt)
Overall code cleanup to remove/replace platform-dependent code (punt)
Replaced potentially unsafe usage of C string stuff like sprintf, vsprintf, vsnprintf, strncat, strcpy and strlen throughout the code with calls to a format() function containing only a single, safe use of vsnprintf, ensuring there's a single place of failure if there's anything to fix and and making it easy to potentially replace this with std::format from C++20 when the time comes. (punt)
Replaced usage of char in many places with std::string (punt)
Started process of replacing UString usage with functions provided through StringUtility instead (punt)
Replaced platform specific fileIO handling in Windows/Linux with cross-platform C++17 standard std::filesystem (punt)
Replaced platform specific time handling by using cross-platform chrono library (punt)
Removed UOX namespace to reduce complexity (punt)
Elimitated template code approach to singletons for more modern c++ constructs, removing dependices in the process (punt)
Removed ODBC support; it hasn't been touched since the initial implementation in 2008, and there is a lack of someone to maintain the code. (punt)
Removed some platform specific files like uoxlinux.h, which is no longer required (punt)
Removed legacy crash protection code, and removed support for cluox (punt)
Removed legacy "support" for Borland compiler (punt)
Removed legacy VC++ 6 Workspace/Project files, VS2005 Solution/Project files, as these are no longer supported (Xuri)
Removed legacy BUILD folder with outdated compilation instructions (Xuri)
Removed old Changelog file (merged into Changelog.txt) (Xuri)
Fixed a pointer bug for items in multis on world load (punt)
Fixed a dictionary related issue that caused segmentation faults on Linux/MacOS (punt)
Fixed an issue with callbacks to JS scripts that caused segmentation faults on Linux/MacOS (punt)
Paths in uox.ini should now load properly on all platforms regardless of whether those paths use slashes or backslashes, and whether or not they end in a slash/backslash. (punt)
Moved to c++17 style of threading, and got rid of threadsafeobject.cpp/h (punt)
Replaced parsing of UOX.INI tags with a system that's more easily maintainable (punt)
Added some new commands to js/commands/custom/misc-cmd.js (Xuri)
cont // Targeted item will be made a container, set to nondecay and movable 2
endfight // Targeted character (and character being fought) will stop fighting
getmulti // Get multiObject for targeted item
finditem // Find item at layer X
movespeed // Set movement speed of target player (0x0 Normal, 0x1 Mounted, 0x2 Slow (walk only), 0x3 Hybrid ("jog"?), 0x4 Frozen)
Added new HTML based documentation in docs folder, and removed many old legacy docs that are either incorporated into this document already or no longer relevant for the current UOX3 version (Xuri)
Co-Authored-By: Charles Kerr <punt1959@users.noreply.github.com>
2020-09-07 18:09:55 +08:00
|
|
|
/* Cope with JSStackFrame.pc value prior to entering js_Interpret. */
|
|
|
|
|
if (!pc)
|
|
|
|
|
return 0;
|
|
|
|
|
|
2018-09-08 18:08:48 +08:00
|
|
|
/*
|
|
|
|
|
* Special case: function definition needs no line number note because
|
|
|
|
|
* the function's script contains its starting line number.
|
|
|
|
|
*/
|
2025-02-05 12:40:54 +10:00
|
|
|
op = js_GetOpcode(cx, script, pc);
|
|
|
|
|
if (js_CodeSpec[op].format & JOF_INDEXBASE)
|
|
|
|
|
pc += js_CodeSpec[op].length;
|
2023-07-12 13:27:26 +10:00
|
|
|
if (*pc == JSOP_DEFFUN) {
|
|
|
|
|
GET_FUNCTION_FROM_BYTECODE(script, pc, 0, fun);
|
Numerous changes with focus on feature and stability parity across Windows, Linux and MacOS platforms
Added new Makefile that handles compiling UOX3 and Spidermonkey on both Linux and MacOS (punt)
Added VS solution (SpiderMonkey.sln) and VC++ project files for compiling SpiderMonkey on Windows (Xuri)
Updated SpiderMonkey from v1.6.0 to v1.7.0
Added optimization flag -O2 for release build in CMakeLists.txt in project root (Xuri)
Added StringUtility file with general common string manipulation functions (punt)
Updated RandomNum function to use a "seedless" random number generator from C++11 instead of the old C rand() function. (punt)
Overall code cleanup to remove/replace platform-dependent code (punt)
Replaced potentially unsafe usage of C string stuff like sprintf, vsprintf, vsnprintf, strncat, strcpy and strlen throughout the code with calls to a format() function containing only a single, safe use of vsnprintf, ensuring there's a single place of failure if there's anything to fix and and making it easy to potentially replace this with std::format from C++20 when the time comes. (punt)
Replaced usage of char in many places with std::string (punt)
Started process of replacing UString usage with functions provided through StringUtility instead (punt)
Replaced platform specific fileIO handling in Windows/Linux with cross-platform C++17 standard std::filesystem (punt)
Replaced platform specific time handling by using cross-platform chrono library (punt)
Removed UOX namespace to reduce complexity (punt)
Elimitated template code approach to singletons for more modern c++ constructs, removing dependices in the process (punt)
Removed ODBC support; it hasn't been touched since the initial implementation in 2008, and there is a lack of someone to maintain the code. (punt)
Removed some platform specific files like uoxlinux.h, which is no longer required (punt)
Removed legacy crash protection code, and removed support for cluox (punt)
Removed legacy "support" for Borland compiler (punt)
Removed legacy VC++ 6 Workspace/Project files, VS2005 Solution/Project files, as these are no longer supported (Xuri)
Removed legacy BUILD folder with outdated compilation instructions (Xuri)
Removed old Changelog file (merged into Changelog.txt) (Xuri)
Fixed a pointer bug for items in multis on world load (punt)
Fixed a dictionary related issue that caused segmentation faults on Linux/MacOS (punt)
Fixed an issue with callbacks to JS scripts that caused segmentation faults on Linux/MacOS (punt)
Paths in uox.ini should now load properly on all platforms regardless of whether those paths use slashes or backslashes, and whether or not they end in a slash/backslash. (punt)
Moved to c++17 style of threading, and got rid of threadsafeobject.cpp/h (punt)
Replaced parsing of UOX.INI tags with a system that's more easily maintainable (punt)
Added some new commands to js/commands/custom/misc-cmd.js (Xuri)
cont // Targeted item will be made a container, set to nondecay and movable 2
endfight // Targeted character (and character being fought) will stop fighting
getmulti // Get multiObject for targeted item
finditem // Find item at layer X
movespeed // Set movement speed of target player (0x0 Normal, 0x1 Mounted, 0x2 Slow (walk only), 0x3 Hybrid ("jog"?), 0x4 Frozen)
Added new HTML based documentation in docs folder, and removed many old legacy docs that are either incorporated into this document already or no longer relevant for the current UOX3 version (Xuri)
Co-Authored-By: Charles Kerr <punt1959@users.noreply.github.com>
2020-09-07 18:09:55 +08:00
|
|
|
return fun->u.i.script->lineno;
|
2018-09-08 18:08:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* General case: walk through source notes accumulating their deltas,
|
|
|
|
|
* keeping track of line-number notes, until we pass the note for pc's
|
|
|
|
|
* offset within script->code.
|
|
|
|
|
*/
|
|
|
|
|
lineno = script->lineno;
|
|
|
|
|
offset = 0;
|
2025-02-05 12:40:54 +10:00
|
|
|
target = pc - script->code;
|
|
|
|
|
for (sn = script->notes(); !SN_IS_TERMINATOR(sn); sn = SN_NEXT(sn)) {
|
2018-09-08 18:08:48 +08:00
|
|
|
offset += SN_DELTA(sn);
|
|
|
|
|
type = (JSSrcNoteType) SN_TYPE(sn);
|
|
|
|
|
if (type == SRC_SETLINE) {
|
|
|
|
|
if (offset <= target)
|
|
|
|
|
lineno = (uintN) js_GetSrcNoteOffset(sn, 0);
|
|
|
|
|
} else if (type == SRC_NEWLINE) {
|
|
|
|
|
if (offset <= target)
|
|
|
|
|
lineno++;
|
|
|
|
|
}
|
|
|
|
|
if (offset > target)
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
return lineno;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* The line number limit is the same as the jssrcnote offset limit. */
|
|
|
|
|
#define SN_LINE_LIMIT (SN_3BYTE_OFFSET_FLAG << 16)
|
|
|
|
|
|
|
|
|
|
jsbytecode *
|
|
|
|
|
js_LineNumberToPC(JSScript *script, uintN target)
|
|
|
|
|
{
|
|
|
|
|
ptrdiff_t offset, best;
|
|
|
|
|
uintN lineno, bestdiff, diff;
|
|
|
|
|
jssrcnote *sn;
|
|
|
|
|
JSSrcNoteType type;
|
|
|
|
|
|
|
|
|
|
offset = 0;
|
|
|
|
|
best = -1;
|
|
|
|
|
lineno = script->lineno;
|
|
|
|
|
bestdiff = SN_LINE_LIMIT;
|
2025-02-05 12:40:54 +10:00
|
|
|
for (sn = script->notes(); !SN_IS_TERMINATOR(sn); sn = SN_NEXT(sn)) {
|
2023-07-12 13:27:26 +10:00
|
|
|
/*
|
|
|
|
|
* Exact-match only if offset is not in the prolog; otherwise use
|
|
|
|
|
* nearest greater-or-equal line number match.
|
|
|
|
|
*/
|
|
|
|
|
if (lineno == target && script->code + offset >= script->main)
|
2018-09-08 18:08:48 +08:00
|
|
|
goto out;
|
2023-07-12 13:27:26 +10:00
|
|
|
if (lineno >= target) {
|
2018-09-08 18:08:48 +08:00
|
|
|
diff = lineno - target;
|
|
|
|
|
if (diff < bestdiff) {
|
|
|
|
|
bestdiff = diff;
|
|
|
|
|
best = offset;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
offset += SN_DELTA(sn);
|
|
|
|
|
type = (JSSrcNoteType) SN_TYPE(sn);
|
|
|
|
|
if (type == SRC_SETLINE) {
|
|
|
|
|
lineno = (uintN) js_GetSrcNoteOffset(sn, 0);
|
|
|
|
|
} else if (type == SRC_NEWLINE) {
|
|
|
|
|
lineno++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (best >= 0)
|
|
|
|
|
offset = best;
|
|
|
|
|
out:
|
|
|
|
|
return script->code + offset;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
JS_FRIEND_API(uintN)
|
|
|
|
|
js_GetScriptLineExtent(JSScript *script)
|
|
|
|
|
{
|
|
|
|
|
uintN lineno;
|
|
|
|
|
jssrcnote *sn;
|
|
|
|
|
JSSrcNoteType type;
|
|
|
|
|
|
|
|
|
|
lineno = script->lineno;
|
2025-02-05 12:40:54 +10:00
|
|
|
for (sn = script->notes(); !SN_IS_TERMINATOR(sn); sn = SN_NEXT(sn)) {
|
2018-09-08 18:08:48 +08:00
|
|
|
type = (JSSrcNoteType) SN_TYPE(sn);
|
|
|
|
|
if (type == SRC_SETLINE) {
|
|
|
|
|
lineno = (uintN) js_GetSrcNoteOffset(sn, 0);
|
|
|
|
|
} else if (type == SRC_NEWLINE) {
|
|
|
|
|
lineno++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return 1 + lineno - script->lineno;
|
|
|
|
|
}
|
2025-03-19 21:25:58 +10:00
|
|
|
|
|
|
|
|
class DisablePrincipalsTranscoding {
|
|
|
|
|
JSSecurityCallbacks *callbacks;
|
|
|
|
|
JSPrincipalsTranscoder temp;
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
DisablePrincipalsTranscoding(JSContext *cx)
|
|
|
|
|
: callbacks(JS_GetRuntimeSecurityCallbacks(cx->runtime)),
|
|
|
|
|
temp(NULL)
|
|
|
|
|
{
|
|
|
|
|
if (callbacks) {
|
|
|
|
|
temp = callbacks->principalsTranscoder;
|
|
|
|
|
callbacks->principalsTranscoder = NULL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
~DisablePrincipalsTranscoding() {
|
|
|
|
|
if (callbacks)
|
|
|
|
|
callbacks->principalsTranscoder = temp;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
JSScript *
|
|
|
|
|
js_CloneScript(JSContext *cx, JSScript *script)
|
|
|
|
|
{
|
|
|
|
|
JS_ASSERT(cx->compartment != script->compartment);
|
|
|
|
|
JS_ASSERT(script->compartment);
|
|
|
|
|
|
|
|
|
|
// serialize script
|
|
|
|
|
JSXDRState *w = JS_XDRNewMem(cx, JSXDR_ENCODE);
|
|
|
|
|
if (!w)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
// we don't want gecko to transcribe our principals for us
|
|
|
|
|
DisablePrincipalsTranscoding disable(cx);
|
|
|
|
|
|
|
|
|
|
if (!JS_XDRScript(w, &script)) {
|
|
|
|
|
JS_XDRDestroy(w);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uint32 nbytes;
|
|
|
|
|
void *p = JS_XDRMemGetData(w, &nbytes);
|
|
|
|
|
if (!p) {
|
|
|
|
|
JS_XDRDestroy(w);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// de-serialize script
|
|
|
|
|
JSXDRState *r = JS_XDRNewMem(cx, JSXDR_DECODE);
|
|
|
|
|
if (!r) {
|
|
|
|
|
JS_XDRDestroy(w);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Hand p off from w to r. Don't want them to share the data
|
|
|
|
|
// mem, lest they both try to free it in JS_XDRDestroy
|
|
|
|
|
JS_XDRMemSetData(r, p, nbytes);
|
|
|
|
|
JS_XDRMemSetData(w, NULL, 0);
|
|
|
|
|
|
|
|
|
|
// We can't use the public API because it makes a script object.
|
|
|
|
|
if (!js_XDRScript(r, &script, NULL))
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
JS_XDRDestroy(r);
|
|
|
|
|
JS_XDRDestroy(w);
|
|
|
|
|
|
|
|
|
|
// set the proper principals for the script
|
|
|
|
|
script->principals = script->compartment->principals;
|
|
|
|
|
if (script->principals)
|
|
|
|
|
JSPRINCIPALS_HOLD(cx, script->principals);
|
|
|
|
|
|
|
|
|
|
return script;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
JSScript::copyClosedSlotsTo(JSScript *other)
|
|
|
|
|
{
|
|
|
|
|
memcpy(other->closedSlots, closedSlots, nClosedArgs + nClosedVars);
|
|
|
|
|
}
|