This Trac instance is not used for development anymore!

We migrated our development workflow to git and Gitea.
To test the future redirection, replace trac by ariadne in the page URL.

Changeset 9852 for ps


Ignore:
Timestamp:
07/17/11 01:24:14 (13 years ago)
Author:
philip
Message:

Upgrade to SpiderMonkey 1.8.5 (fixes #734)

Location:
ps/trunk
Files:
1 added
27 edited

Legend:

Unmodified
Added
Removed
  • ps/trunk/build/premake/extern_libs.lua

    r9574 r9852  
    191191                include_dir = "include-unix"
    192192            end
    193             tinsert(package.config["Debug"  ].includepaths, libraries_dir.."spidermonkey-tip/"..include_dir.."/debug")
    194             tinsert(package.config["Testing"].includepaths, libraries_dir.."spidermonkey-tip/"..include_dir.."/debug")
    195             tinsert(package.config["Release"].includepaths, libraries_dir.."spidermonkey-tip/"..include_dir.."/release")
    196             tinsert(package.libpaths, libraries_dir.."spidermonkey-tip/lib")
    197             tinsert(package.config["Debug"  ].links, "mozjs-ps-debug")
    198             tinsert(package.config["Testing"].links, "mozjs-ps-release")
    199             tinsert(package.config["Release"].links, "mozjs-ps-release")
     193            tinsert(package.config["Debug"  ].includepaths, libraries_dir.."spidermonkey/"..include_dir)
     194            tinsert(package.config["Testing"].includepaths, libraries_dir.."spidermonkey/"..include_dir)
     195            tinsert(package.config["Release"].includepaths, libraries_dir.."spidermonkey/"..include_dir)
     196            tinsert(package.libpaths, libraries_dir.."spidermonkey/lib")
     197            tinsert(package.config["Debug"  ].links, "mozjs185-ps-debug")
     198            tinsert(package.config["Testing"].links, "mozjs185-ps-release")
     199            tinsert(package.config["Release"].links, "mozjs185-ps-release")
    200200        end,
    201201    },
  • ps/trunk/build/premake/extern_libs4.lua

    r9830 r9852  
    486486            end
    487487            configuration "Debug"
    488                 includedirs { libraries_dir.."spidermonkey-tip/"..include_dir.."/debug" }
     488                includedirs { libraries_dir.."spidermonkey/"..include_dir }
    489489            configuration "Testing"
    490                 includedirs { libraries_dir.."spidermonkey-tip/"..include_dir.."/debug" }
     490                includedirs { libraries_dir.."spidermonkey/"..include_dir }
    491491            configuration "Release"
    492                 includedirs { libraries_dir.."spidermonkey-tip/"..include_dir.."/release" }
     492                includedirs { libraries_dir.."spidermonkey/"..include_dir }
    493493            configuration { }
    494494        end,
    495495        link_settings = function()
    496496            configuration "Debug"
    497                 links { "mozjs-ps-debug" }
     497                links { "mozjs185-ps-debug" }
    498498            configuration "Testing"
    499                 links { "mozjs-ps-debug" }
     499                links { "mozjs185-ps-debug" }
    500500            configuration "Release"
    501                 links { "mozjs-ps-release" }
     501                links { "mozjs185-ps-release" }
    502502            configuration { }
    503             add_default_lib_paths("spidermonkey-tip")
     503            add_default_lib_paths("spidermonkey")
    504504        end,
    505505    },
  • ps/trunk/build/workspaces/update-workspaces-new.sh

    r9830 r9852  
    5151(cd ../../libraries/fcollada/src && make ${JOBS}) || die "FCollada build failed"
    5252echo
    53 (cd ../../libraries/spidermonkey-tip && JOBS=${JOBS} ./build.sh) || die "SpiderMonkey build failed"
     53(cd ../../libraries/spidermonkey && JOBS=${JOBS} ./build.sh) || die "SpiderMonkey build failed"
    5454echo
    5555if [ "$with_system_nvtt" = "false" ]; then
  • ps/trunk/build/workspaces/update-workspaces.sh

    r9766 r9852  
    5050(cd ../../libraries/fcollada/src && make ${JOBS}) || die "FCollada build failed"
    5151echo
    52 (cd ../../libraries/spidermonkey-tip && JOBS=${JOBS} ./build.sh) || die "SpiderMonkey build failed"
     52(cd ../../libraries/spidermonkey && JOBS=${JOBS} ./build.sh) || die "SpiderMonkey build failed"
    5353echo
    5454if [ "$with_system_nvtt" = "false" ]; then
  • ps/trunk/source/gui/CGUI.cpp

    r9362 r9852  
    326326}
    327327
    328 static JSBool SetGlobalProperty(JSContext* cx, JSObject* UNUSED(obj), jsid id, jsval* vp)
     328static JSBool SetGlobalProperty(JSContext* cx, JSObject* UNUSED(obj), jsid id, JSBool UNUSED(strict), jsval* vp)
    329329{
    330330    return JS_SetPropertyById(cx, g_ScriptingHost.GetGlobalObject(), id, vp);
     
    377377static JSClass page_global_class = {
    378378    "page_global", JSCLASS_GLOBAL_FLAGS | JSCLASS_NEW_RESOLVE,
    379     JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_PropertyStub,
     379    JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_StrictPropertyStub,
    380380    JS_EnumerateStub, (JSResolveOp)ResolveGlobalProperty, JS_ConvertStub, JS_FinalizeStub,
    381381    NULL, NULL, NULL, NULL,
  • ps/trunk/source/gui/IGUIObject.h

    r9340 r9852  
    147147    // Allow getProperty to access things like GetParent()
    148148    friend JSBool JSI_IGUIObject::getProperty(JSContext* cx, JSObject* obj, jsid id, jsval* vp);
    149     friend JSBool JSI_IGUIObject::setProperty(JSContext* cx, JSObject* obj, jsid id, jsval* vp);
     149    friend JSBool JSI_IGUIObject::setProperty(JSContext* cx, JSObject* obj, jsid id, JSBool strict, jsval* vp);
    150150
    151151public:
  • ps/trunk/source/gui/scripting/JSInterface_GUITypes.cpp

    r8929 r9852  
    2525    "GUISize", 0,
    2626        JS_PropertyStub, JS_PropertyStub,
    27         JS_PropertyStub, JS_PropertyStub,
     27        JS_PropertyStub, JS_StrictPropertyStub,
    2828        JS_EnumerateStub, JS_ResolveStub,
    2929        JS_ConvertStub, JS_FinalizeStub,
     
    138138    "GUIColor", 0,
    139139        JS_PropertyStub, JS_PropertyStub,
    140         JS_PropertyStub, JS_PropertyStub,
     140        JS_PropertyStub, JS_StrictPropertyStub,
    141141        JS_EnumerateStub, JS_ResolveStub,
    142142        JS_ConvertStub, JS_FinalizeStub,
     
    215215    "GUIMouse", 0,
    216216        JS_PropertyStub, JS_PropertyStub,
    217         JS_PropertyStub, JS_PropertyStub,
     217        JS_PropertyStub, JS_StrictPropertyStub,
    218218        JS_EnumerateStub, JS_ResolveStub,
    219219        JS_ConvertStub, JS_FinalizeStub,
  • ps/trunk/source/gui/scripting/JSInterface_IGUIObject.cpp

    r9423 r9852  
    291291}
    292292
    293 JSBool JSI_IGUIObject::setProperty(JSContext* cx, JSObject* obj, jsid id, jsval* vp)
     293JSBool JSI_IGUIObject::setProperty(JSContext* cx, JSObject* obj, jsid id, JSBool UNUSED(strict), jsval* vp)
    294294{
    295295    IGUIObject* e = (IGUIObject*)JS_GetInstancePrivate(cx, obj, &JSI_IGUIObject::JSI_class, NULL);
  • ps/trunk/source/gui/scripting/JSInterface_IGUIObject.h

    r8629 r9852  
    2727    extern JSFunctionSpec JSI_methods[];
    2828    JSBool getProperty(JSContext* cx, JSObject* obj, jsid id, jsval* vp);
    29     JSBool setProperty(JSContext* cx, JSObject* obj, jsid id, jsval* vp);
     29    JSBool setProperty(JSContext* cx, JSObject* obj, jsid id, JSBool strict, jsval* vp);
    3030    JSBool construct(JSContext* cx, uintN argc, jsval* vp);
    3131    JSBool toString(JSContext* cx, uintN argc, jsval* vp);
  • ps/trunk/source/maths/scripting/JSInterface_Vector3D.cpp

    r8629 r9852  
    126126}
    127127
    128 JSBool JSI_Vector3D::setProperty(JSContext* cx, JSObject* obj, jsid id, jsval* vp)
     128JSBool JSI_Vector3D::setProperty(JSContext* cx, JSObject* obj, jsid id, JSBool UNUSED(strict), jsval* vp)
    129129{
    130130    if (!JSID_IS_INT(id))
  • ps/trunk/source/maths/scripting/JSInterface_Vector3D.h

    r8629 r9852  
    5858
    5959    JSBool getProperty(JSContext* cx, JSObject* obj, jsid id, jsval* vp);
    60     JSBool setProperty(JSContext* cx, JSObject* obj, jsid id, jsval* vp);
     60    JSBool setProperty(JSContext* cx, JSObject* obj, jsid id, JSBool strict, jsval* vp);
    6161    void finalize(JSContext* cx, JSObject* obj);
    6262    JSBool construct(JSContext* cx, uintN argc, jsval* vp);
  • ps/trunk/source/ps/ConfigDB.cpp

    r9410 r9852  
    6161    }
    6262
    63     JSBool SetProperty(JSContext* cx, JSObject* obj, jsid id, jsval* vp)
     63    JSBool SetProperty(JSContext* cx, JSObject* obj, jsid id, JSBool UNUSED(strict), jsval* vp)
    6464    {
    6565        EConfigNamespace cfgNs = GET_NS_PRIVATE(cx, obj);
     
    170170        "ConfigDB", 0,
    171171        JS_PropertyStub, JS_PropertyStub,
    172         JS_PropertyStub, JS_PropertyStub,
     172        JS_PropertyStub, JS_StrictPropertyStub,
    173173        JS_EnumerateStub, JS_ResolveStub,
    174174        JS_ConvertStub, JS_FinalizeStub
  • ps/trunk/source/ps/scripting/JSInterface_Console.cpp

    r8629 r9852  
    6363}
    6464
    65 JSBool JSI_Console::setProperty(JSContext* UNUSED(cx), JSObject* UNUSED(obj), jsid id, jsval* vp)
     65JSBool JSI_Console::setProperty(JSContext* UNUSED(cx), JSObject* UNUSED(obj), jsid id, JSBool UNUSED(strict), jsval* vp)
    6666{
    6767    if (!JSID_IS_INT(id))
  • ps/trunk/source/ps/scripting/JSInterface_Console.h

    r8629 r9852  
    3636
    3737    JSBool getProperty(JSContext* cx, JSObject* obj, jsid id, jsval* vp);
    38     JSBool setProperty(JSContext* cx, JSObject* obj, jsid id, jsval* vp);
     38    JSBool setProperty(JSContext* cx, JSObject* obj, jsid id, JSBool strict, jsval* vp);
    3939
    4040    JSBool getConsole(JSContext* context, JSObject* obj, jsid id, jsval* vp);
  • ps/trunk/source/scripting/ScriptableObject.h

    r9362 r9852  
    408408        return( JS_TRUE );
    409409    }
    410     static JSBool JSSetProperty( JSContext* cx, JSObject* obj, jsid id, jsval* vp )
     410    static JSBool JSSetProperty( JSContext* cx, JSObject* obj, jsid id, JSBool UNUSED(strict), jsval* vp )
    411411    {
    412412        T* Instance = ToNative<T>( cx, obj );
  • ps/trunk/source/scripting/ScriptingHost.cpp

    r9107 r9852  
    209209        throw PSERROR_Scripting_ConversionFailed();
    210210
    211     jschar *strptr=JS_GetStringChars(string);
    212     size_t length=JS_GetStringLength(string);
     211    size_t length;
     212    const jschar *strptr = JS_GetStringCharsAndLength(m_Context, string, &length);
     213    if (!strptr)
     214        throw PSERROR_Scripting_ConversionFailed();
     215
    213216    return std::wstring(strptr, strptr+length);
    214217}
  • ps/trunk/source/scriptinterface/NativeWrapperDefns.h

    r9362 r9852  
    7373
    7474// Fast natives don't trigger the hook we use for profiling, so explicitly
    75 // notify the profiler when these functions are being called
     75// notify the profiler when these functions are being called.
     76// ScriptInterface_impl::Register stores the name in a reserved slot.
     77// (TODO: this doesn't work for functions registered via InterfaceScripted.h.
     78// Maybe we should do some interned JS_GetFunctionId thing.)
    7679#if ENABLE_SCRIPT_PROFILING
    7780#define SCRIPT_PROFILE \
    7881    ENSURE(JSVAL_IS_OBJECT(JS_CALLEE(cx, vp)) && JS_ObjectIsFunction(cx, JSVAL_TO_OBJECT(JS_CALLEE(cx, vp)))); \
    79     const char* name = JS_GetFunctionName(JS_ValueToFunction(cx, JS_CALLEE(cx, vp))); /* native function so ValueToFunction is safe; this makes unsafe lifetime assumptions */ \
     82    const char* name = "(unknown)"; \
     83    jsval nameval; \
     84    if (JS_GetReservedSlot(cx, JSVAL_TO_OBJECT(JS_CALLEE(cx, vp)), 0, &nameval) \
     85        && !JSVAL_IS_VOID(nameval)) \
     86        name = static_cast<const char*>(JSVAL_TO_PRIVATE(nameval)); \
    8087    CProfileSampleScript profile(name);
    8188#else
  • ps/trunk/source/scriptinterface/ScriptConversions.cpp

    r9664 r9852  
    2424#include "ps/CLogger.h"
    2525#include "ps/CStr.h"
    26 
    27 #include "js/jsapi.h"
    28 
    29 #define signbit std::signbit
    30 #include "js/jstypedarray.h"
    31 #undef signbit
     26#include "scriptinterface/ScriptExtraHeaders.h" // for typed arrays
    3227
    3328#define FAIL(msg) STMT(JS_ReportError(cx, msg); return false)
     
    115110    if (!ret)
    116111        FAIL("Argument must be convertible to a string");
    117     jschar* ch = JS_GetStringChars(ret);
    118     out = std::wstring(ch, ch + JS_GetStringLength(ret));
     112    size_t length;
     113    const jschar* ch = JS_GetStringCharsAndLength(cx, ret, &length);
     114    if (!ch)
     115        FAIL("JS_GetStringsCharsAndLength failed"); // out of memory
     116    out = std::wstring(ch, ch + length);
    119117    return true;
    120118}
  • ps/trunk/source/scriptinterface/ScriptInterface.cpp

    r9699 r9852  
    4646#define STACK_CHUNK_SIZE 8192
    4747
    48 #if ENABLE_SCRIPT_PROFILING
    49 # define signbit std::signbit
    50 # include "js/jsdbgapi.h"
    51 # undef signbit
    52 #endif
     48#include "scriptinterface/ScriptExtraHeaders.h"
    5349
    5450////////////////////////////////////////////////////////////////
     
    5854public:
    5955    ScriptRuntime(int runtimeSize) :
    60         m_rooter(NULL)
     56        m_rooter(NULL), m_compartmentGlobal(NULL)
    6157    {
    6258        m_rt = JS_NewRuntime(runtimeSize);
     
    8581    JSRuntime* m_rt;
    8682    AutoGCRooter* m_rooter;
     83
     84    JSObject* m_compartmentGlobal;
    8785
    8886private:
     
    228226    JSObject* m_glob; // global scope object
    229227    JSObject* m_nativeScope; // native function scope object
     228    JSCrossCompartmentCall* m_call;
    230229};
    231230
     
    235234JSClass global_class = {
    236235    "global", JSCLASS_GLOBAL_FLAGS,
    237     JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_PropertyStub,
     236    JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_StrictPropertyStub,
    238237    JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, JS_FinalizeStub,
    239238    NULL, NULL, NULL, NULL,
     
    266265        // TODO: this violates the docs ("The error reporter callback must not reenter the JSAPI.")
    267266
     267        // Hide the exception from EvaluateScript
     268        JSExceptionState* excnState = JS_SaveExceptionState(cx);
     269        JS_ClearPendingException(cx);
     270
    268271        jsval rval;
    269272        const char dumpStack[] = "this.stack.trimRight().replace(/^/mg, '  ')"; // indent each line
     
    273276            if (ScriptInterface::FromJSVal(cx, rval, stackTrace))
    274277                msg << "\n" << stackTrace;
     278
     279            JS_RestoreExceptionState(cx, excnState);
     280        }
     281        else
     282        {
     283            // Error got replaced by new exception from EvaluateScript
     284            JS_DropExceptionState(cx, excnState);
    275285        }
    276286    }
     
    358368
    359369    jsval ret;
    360     if (!JS_StructuredClone(cx, JS_ARGV(cx, vp)[0], &ret))
     370
     371    // We'd usually do:
     372    //  if (!JS_StructuredClone(cx, JS_ARGV(cx, vp)[0], &ret, NULL, NULL))
     373    //      return JS_FALSE;
     374    // but that function is broken in the 1.8.5 release
     375    // (https://bugzilla.mozilla.org/show_bug.cgi?id=651510)
     376    // so do an equivalent operation with a different API:
     377    JSAutoStructuredCloneBuffer buf;
     378    if (!buf.write(cx, JS_ARGV(cx, vp)[0]) || !buf.read(&ret, cx))
    361379        return JS_FALSE;
    362380
     
    464482    JS_BeginRequest(m_cx);
    465483
    466     m_glob = JS_NewGlobalObject(m_cx, &global_class);
     484    // We only want a single compartment per runtime
     485    if (m_runtime->m_compartmentGlobal)
     486    {
     487        m_call = JS_EnterCrossCompartmentCall(m_cx, m_runtime->m_compartmentGlobal);
     488        m_glob = JS_NewGlobalObject(m_cx, &global_class);
     489    }
     490    else
     491    {
     492        m_call = NULL;
     493        m_glob = JS_NewCompartmentAndGlobalObject(m_cx, &global_class, NULL);
     494        m_runtime->m_compartmentGlobal = m_glob;
     495    }
     496
    467497    ok = JS_InitStandardClasses(m_cx, m_glob);
    468498    ENSURE(ok);
     
    486516ScriptInterface_impl::~ScriptInterface_impl()
    487517{
     518    if (m_call)
     519        JS_LeaveCrossCompartmentCall(m_call);
    488520    JS_EndRequest(m_cx);
    489521    JS_DestroyContext(m_cx);
     
    492524void ScriptInterface_impl::Register(const char* name, JSNative fptr, uintN nargs)
    493525{
    494     JS_DefineFunction(m_cx, m_nativeScope, name, fptr, nargs, JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT);
     526    JSFunction* func = JS_DefineFunction(m_cx, m_nativeScope, name, fptr, nargs, JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT);
     527
     528    if (!func)
     529        return;
     530
     531#if ENABLE_SCRIPT_PROFILING
     532    // Store the function name in a slot, so we can pass it to the profiler.
     533
     534    // Use a flyweight std::string because we can't assume the caller has
     535    // a correctly-aligned string and that its lifetime is long enough
     536    typedef boost::flyweight<
     537        std::string,
     538        boost::flyweights::no_tracking
     539        // can't use no_locking; Register might be called in threads
     540    > LockedStringFlyweight;
     541
     542    LockedStringFlyweight fw(name);
     543    JS_SetReservedSlot(m_cx, JS_GetFunctionObject(func), 0, PRIVATE_TO_JSVAL((void*)fw.get().c_str()));
     544#endif
    495545}
    496546
     
    763813
    764814        JSString* name = JSVAL_TO_STRING(val);
    765         size_t len = JS_GetStringLength(name);
    766         jschar* chars = JS_GetStringChars(name);
    767         if (len >= prefix16.size() && memcmp(chars, prefix16.c_str(), prefix16.size()*2) == 0)
     815        size_t len;
     816        const jschar* chars = JS_GetStringCharsAndLength(m->m_cx, name, &len);
     817        if (chars && len >= prefix16.size() && memcmp(chars, prefix16.c_str(), prefix16.size()*2) == 0)
    768818            out.push_back(std::string(chars, chars+len)); // handles Unicode poorly
    769819    }
     
    11031153        if (JSVAL_IS_STRING(val))
    11041154        {
    1105             JSString* str = JS_NewUCStringCopyN(cxTo, JS_GetStringChars(JSVAL_TO_STRING(val)), JS_GetStringLength(JSVAL_TO_STRING(val)));
     1155            size_t len;
     1156            const jschar* chars = JS_GetStringCharsAndLength(cxFrom, JSVAL_TO_STRING(val), &len);
     1157            CLONE_REQUIRE(chars, L"JS_GetStringCharsAndLength");
     1158            JSString* str = JS_NewUCStringCopyN(cxTo, chars, len);
    11061159            CLONE_REQUIRE(str, L"JS_NewUCStringCopyN");
    11071160            jsval rval = STRING_TO_JSVAL(str);
     
    11541207                JSString* idstr = JS_ValueToString(cxFrom, idval);
    11551208                CLONE_REQUIRE(idstr, L"JS_ValueToString (id)");
    1156                 CLONE_REQUIRE(JS_SetUCProperty(cxTo, newObj, JS_GetStringChars(idstr), JS_GetStringLength(idstr), &newPropval), L"JS_SetUCProperty");
     1209                size_t len;
     1210                const jschar* chars = JS_GetStringCharsAndLength(cxFrom, idstr, &len);
     1211                CLONE_REQUIRE(idstr, L"JS_GetStringCharsAndLength (id)");
     1212                CLONE_REQUIRE(JS_SetUCProperty(cxTo, newObj, chars, len, &newPropval), L"JS_SetUCProperty");
    11571213            }
    11581214            else
     
    11961252    uint64* data = NULL;
    11971253    size_t nbytes = 0;
    1198     if (!JS_WriteStructuredClone(m->m_cx, v, &data, &nbytes))
     1254    if (!JS_WriteStructuredClone(m->m_cx, v, &data, &nbytes, NULL, NULL))
    11991255        return shared_ptr<StructuredClone>();
    12001256    // TODO: should we have better error handling?
     
    12111267{
    12121268    jsval ret = JSVAL_VOID;
    1213     JS_ReadStructuredClone(m->m_cx, ptr->m_Data, ptr->m_Size, &ret);
     1269    JS_ReadStructuredClone(m->m_cx, ptr->m_Data, ptr->m_Size, JS_STRUCTURED_CLONE_VERSION, &ret, NULL, NULL);
    12141270    return ret;
    12151271}
  • ps/trunk/source/scriptinterface/ScriptTypes.h

    r9827 r9852  
    1 /* Copyright (C) 2010 Wildfire Games.
     1/* Copyright (C) 2011 Wildfire Games.
    22 * This file is part of 0 A.D.
    33 *
     
    4848#endif
    4949
     50// Ignore some harmless warnings triggered by jsapi.h
     51#if GCC_VERSION >= 402 // (older GCCs don't support this pragma)
     52# pragma GCC diagnostic ignored "-Wunused-parameter"
     53# pragma GCC diagnostic ignored "-Wredundant-decls"
     54#endif
     55#if MSC_VERSION
     56# pragma warning(push)
     57# pragma warning(disable:4480) // "nonstandard extension used: specifying underlying type for enum"
     58# pragma warning(disable:4100) // "unreferenced formal parameter"
     59#endif
     60
    5061#include "js/jsapi.h"
     62
     63#if MSC_VERSION
     64# pragma warning(pop)
     65#endif
     66#if GCC_VERSION >= 402
     67# pragma GCC diagnostic warning "-Wunused-parameter"
     68# pragma GCC diagnostic warning "-Wredundant-decls"
     69#endif
    5170
    5271#if JS_VERSION != 185
  • ps/trunk/source/simulation2/components/CCmpAIManager.cpp

    r9720 r9852  
    9191            // Clean up rooted objects before destroying their script context
    9292            m_Obj = CScriptValRooted();
     93            m_Commands.clear();
    9394        }
    9495
     
    271272        m_PlayerMetadata.clear();
    272273        m_Players.clear();
     274        m_GameState.reset();
     275        m_GameStateMapVal = CScriptValRooted();
    273276    }
    274277
  • ps/trunk/source/simulation2/scripting/EngineScriptConversions.cpp

    r9362 r9852  
    1919
    2020#include "scriptinterface/ScriptInterface.h"
     21#include "scriptinterface/ScriptExtraHeaders.h" // for typed arrays
    2122
    2223#include "maths/Fixed.h"
     
    2930#include "simulation2/system/IComponent.h"
    3031#include "simulation2/system/ParamNode.h"
    31 
    32 #include "js/jsapi.h"
    33 
    34 #define signbit std::signbit
    35 #include "js/jstypedarray.h"
    36 #undef signbit
    3732
    3833#define FAIL(msg) STMT(JS_ReportError(cx, msg); return false)
  • ps/trunk/source/simulation2/serialization/BinarySerializer.cpp

    r9363 r9852  
    2626
    2727#include "scriptinterface/ScriptInterface.h"
    28 
    29 #define signbit std::signbit
    30 #include "js/jsvalue.h" // for JSDOUBLE_IS_INT32
    31 #undef signbit
     28#include "scriptinterface/ScriptExtraHeaders.h" // for JSDOUBLE_IS_INT32
    3229
    3330CBinarySerializerScriptImpl::CBinarySerializerScriptImpl(ScriptInterface& scriptInterface, ISerializer& serializer) :
     
    189186void CBinarySerializerScriptImpl::ScriptString(const char* name, JSString* string)
    190187{
    191     jschar* chars = JS_GetStringChars(string);
    192     size_t length = JS_GetStringLength(string);
     188    JSContext* cx = m_ScriptInterface.GetContext();
     189    size_t length;
     190    const jschar* chars = JS_GetStringCharsAndLength(cx, string, &length);
     191
     192    if (!chars)
     193        throw PSERROR_Serialize_ScriptError("JS_GetStringCharsAndLength failed");
    193194
    194195#if BYTE_ORDER != LITTLE_ENDIAN
  • ps/trunk/source/simulation2/system/InterfaceScripted.h

    r8629 r9852  
    2525    JSClass class_ICmp##iname = { \
    2626        "ICmp" #iname, JSCLASS_HAS_PRIVATE, \
    27         JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, \
     27        JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_StrictPropertyStub, \
    2828        JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, JS_FinalizeStub, \
    2929        JSCLASS_NO_OPTIONAL_MEMBERS \
  • ps/trunk/source/tools/atlas/AtlasObject/AtlasObjectJS.cpp

    r9566 r9852  
    7272            return obj; // error
    7373        size_t valueLen;
    74         const jschar* valueChars = JS_GetStringCharsAndLength(str, &valueLen);
     74        const jschar* valueChars = JS_GetStringCharsAndLength(cx, str, &valueLen);
    7575        if (!valueChars)
    7676            return obj; // error
     
    112112
    113113        JSString* name = JSVAL_TO_STRING(val);
    114         size_t len = JS_GetStringLength(name);
    115         jschar* chars = JS_GetStringChars(name);
    116         wxString nameWx(reinterpret_cast<char*>(chars), wxMBConvUTF16(), len*2);
     114        size_t len;
     115        const jschar* chars = JS_GetStringCharsAndLength(cx, name, &len);
     116        wxString nameWx(reinterpret_cast<const char*>(chars), wxMBConvUTF16(), len*2);
    117117        std::string nameStr(nameWx.ToUTF8().data());
    118118
  • ps/trunk/source/tools/atlas/AtlasScript/ScriptInterface.cpp

    r9827 r9852  
    2424#endif
    2525
    26 #include "js/jsapi.h"
    27 
    28 #ifdef _WIN32
    29 # pragma warning(disable: 4996) // avoid complaints about deprecated localtime
    30 #endif
    31 
    3226#include "wx/wx.h"
    3327
     
    144138            if (! ret)
    145139                FAIL("Argument must be convertible to a string");
    146             jschar* ch = JS_GetStringChars(ret);
    147             out = std::wstring(ch, ch+JS_GetStringLength(ret));
     140            size_t len;
     141            const jschar* ch = JS_GetStringCharsAndLength(cx, ret, &len);
     142            if (! ch)
     143                FAIL("JS_GetStringsCharsAndLength failed"); // probably out of memory
     144            out = std::wstring(ch, ch + len);
    148145            return true;
    149146        }
     
    157154            if (! ret)
    158155                FAIL("Argument must be convertible to a string");
     156            size_t len = JS_GetStringEncodingLength(cx, ret);
     157            if (len == (size_t)-1)
     158                FAIL("JS_GetStringEncodingLength failed");
    159159            char* ch = JS_EncodeString(cx, ret); // chops off high byte of each jschar
    160160            if (! ch)
    161                 FAIL("JS_EncodeString failed"); // out of memory
    162             out = std::string(ch, ch + JS_GetStringLength(ret));
     161                FAIL("JS_EncodeString failed"); // probably out of memory
     162            out = std::string(ch, ch + len);
    163163            JS_free(cx, ch);
    164164            return true;
     
    171171        {
    172172            JSString* ret = JS_ValueToString(cx, v);
     173            size_t len;
    173174            if (! ret)
    174175                FAIL("Argument must be convertible to a string");
    175             jschar* ch = JS_GetStringChars(ret);
    176             out = wxString((const char*)ch, wxMBConvUTF16(), (size_t)(JS_GetStringLength(ret)*2));
     176            const jschar* ch = JS_GetStringCharsAndLength(cx, ret, &len);
     177            if (! ch)
     178                FAIL("JS_GetStringsCharsAndLength failed"); // probably out of memory
     179            out = wxString((const char*)ch, wxMBConvUTF16(), len*2);
    177180            return true;
    178181        }
     
    372375    JSClass global_class = {
    373376        "global", JSCLASS_GLOBAL_FLAGS,
    374         JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_PropertyStub,
     377        JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_StrictPropertyStub,
    375378        JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, JS_FinalizeStub,
    376379        NULL, NULL, NULL, NULL,
     
    417420        JSString* code = JSVAL_TO_STRING(JS_ARGV(cx, vp)[1]);
    418421       
     422        size_t len;
     423        const jschar* ch = JS_GetStringCharsAndLength(cx, code, &len);
     424        if (!ch)
     425            return JS_FALSE;
     426
    419427        jsval rval = JSVAL_VOID;
    420428        if (!AtlasScriptInterface_impl::LoadScript(cx,
    421                 JS_GetStringChars(code), (uintN)JS_GetStringLength(code),
     429                ch, (uintN)len,
    422430                name.c_str(), &rval))
    423431            return JS_FALSE;
     
    466474    JS_SetVersion(m_cx, JSVERSION_LATEST);
    467475
    468     m_glob = JS_NewGlobalObject(m_cx, &global_class);
     476    m_glob = JS_NewCompartmentAndGlobalObject(m_cx, &global_class, NULL);
    469477    JS_InitStandardClasses(m_cx, m_glob);
    470478   
  • ps/trunk/source/tools/atlas/AtlasScript/ScriptInterface.h

    r9567 r9852  
    3232#endif // (we don't support XP_OS2 or XP_BEOS)
    3333
     34#ifdef __GNUC__
     35# define GCC_VERSION (__GNUC__*100 + __GNUC_MINOR__)
     36#else
     37# define GCC_VERSION 0
     38#endif
     39
     40#ifdef _MSC_VER
     41# define MSC_VERSION _MSC_VER
     42#else
     43# define MSC_VERSION 0
     44#endif
     45
     46// Ignore some harmless warnings triggered by jsapi.h
     47#if GCC_VERSION >= 402 // (older GCCs don't support this pragma)
     48# pragma GCC diagnostic ignored "-Wunused-parameter"
     49# pragma GCC diagnostic ignored "-Wredundant-decls"
     50#endif
     51#if MSC_VERSION
     52# pragma warning(push)
     53# pragma warning(disable:4480) // "nonstandard extension used: specifying underlying type for enum"
     54# pragma warning(disable:4100) // "unreferenced formal parameter"
     55#endif
     56
    3457#include "js/jsapi.h"
     58
     59#if MSC_VERSION
     60# pragma warning(pop)
     61#endif
     62#if GCC_VERSION >= 402
     63# pragma GCC diagnostic warning "-Wunused-parameter"
     64# pragma GCC diagnostic warning "-Wredundant-decls"
     65#endif
    3566
    3667class wxString;
Note: See TracChangeset for help on using the changeset viewer.