Skip to content
This repository has been archived by the owner on Dec 1, 2020. It is now read-only.

Migrating to v25

Michael Boccara edited this page Feb 12, 2014 · 13 revisions

Changes needed to migrate to SpiderMonkey v25 from v23

Misc Changes

Compiler update

SpiderMonkey uses static_assert in some header files. So projects that use SpiderMonkey like JS Bindings needs to update its compiler to a C++11 compiler.

API Changes

JS_Init

JS_Init() needs to be called at the very beginning.

Also, it is strongly recommended, in your JS setup function, to take inspiration from the example code in js/src/gdb/gdb-tests.cpp

JS_SetProperty / JS_GetProperty

JS_SetProperty and JS_GetProperty no longer work with jsval objects. Instead now receives JS::RootedValue objects.

// Old Way
jsval someJSval = OBJECT_TO_JSVAL(someObject);
JS_SetProperty(cx, object, "cp", &someJSval);
JS_GetProperty(cx, object, "cp", &someJSval);

// New Way
JS::RootedValue someJSval(_cx);
someJSval = OBJECT_TO_JSVAL(someObject);
JS_SetProperty(cx, object, "cp", someJSval);
JS_GetProperty(cx, object, "cp", &someJSval);

JS_NewGlobalObject

// Old Way
JS_NewGlobalObject(cx, &global_class, NULL);

// New Way
JS_NewGlobalObject(cx, &global_class, NULL, JS::DontFireOnNewGlobalHook /* or JS::FireOnNewGlobalHook */);

JS_GetGlobalObject

// Old Way
JS_GetGlobalObject(cx);

// New Way
JS_GetGlobalForCompartmentOrNull(cx, js::GetContextCompartment(cx));
//or
JS_GetGlobalForObject(cx, jsobject_ptr); // if you have a current object

For more explanations see this [page: https://developer.mozilla.org/en-US/docs/Mozilla/Projects/SpiderMonkey/JSAPI_reference/JS_GetGlobalObject

Although it is not up to date as JS_GetGlobalForCompartmentOrNull has replaced JS_GetGlobalForScopeChain...

JS_SetVersion

// Old Way
JS_SetVersion(_cx, JSVERSION_LATEST);

// New Way
#include "jsfriendapi.h"
...
JSCompartment *compartment = js::GetContextCompartment(cx);
if(compartment != NULL)
    JS_SetVersionForCompartment(compartment, JSVERSION_LATEST);
else
    // well, don't know what to do here...

Also, it must be called from within a

JSClass

// Old Way
    clazz =
    {
        getClassName().c_str(),
        JSCLASS_HAS_PRIVATE,
        JS_PropertyStub,
        JS_PropertyStub,
        JS_PropertyStub,
        JS_StrictPropertyStub,
        JS_EnumerateStub,
        JS_ResolveStub,
        JS_ConvertStub,
        NULL,
        JSCLASS_NO_OPTIONAL_MEMBERS
    };

// New Way: JS_DeletePropertyStub instead of JS_PropertyStub because the 4th member is a JS_DeletePropertyOp
    clazz =
    {
        getClassName().c_str(),
        JSCLASS_HAS_PRIVATE,
        JS_PropertyStub,
        JS_DeletePropertyStub,
        JS_PropertyStub,
        JS_StrictPropertyStub,
        JS_EnumerateStub,
        JS_ResolveStub,
        JS_ConvertStub,
        NULL,
        JSCLASS_NO_OPTIONAL_MEMBERS
    };

JS::CallArgs

// Old Way
    JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
    JS::Value& val = args[0];

// New way
    JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
    JS::MutableHandleValue mhval = args[0];
    const JS::Value& cval = args[0].get();
    JS::Value& val = *args[0].address();

Patched files

build-*

Adds build-ios, build-osx, build-android and build-win32 scripts

configure.in, configure, aclocal.m4, ios.m4

Adds iOS options

Android.mk

Needed to compile Android

Disables LLVM PR8927 check

Backport 911893 bug fix

https://github.com/ricardoquesada/Spidermonkey/commit/0e492ed44a628df4688d642b06244807b159eaec

Patches for vm/Runtime.h

https://github.com/ricardoquesada/Spidermonkey/commit/729cde6171ad84c7679b28f29ed4d2957e215e2f https://github.com/ricardoquesada/Spidermonkey/commit/33a2f81c7f3ab35cce10435063161b84890b663c

vm/NumericConversions.h

Disables ARM assembly optimizations when using clang

Forces JS_NO_JSVAL_JSID_STRUCT_TYPES in jspubtd.h

Disables "DEBUG" class id in order to have ABI compatibility between DEBUG and RELEASE builds

js::IsInRequest available in RELEASE mode

https://github.com/ricardoquesada/Spidermonkey/commit/333f7ffd9674b9c114a0724f97a8567cc7c4eb07

arm64 bit support

https://github.com/ricardoquesada/Spidermonkey/commit/35f74c893133cd674a425e2ebbd204ee63c64824

Clone this wiki locally