[jsc-dev] Need help with some issues running on android

shuan zhao hszhsh at icloud.com
Wed Dec 28 02:20:05 PST 2016


Hi,
	I’m trying to port JavaScriptCore to android and use it in my project. I have built the library successfully, but encountered some issues when running my project. I have no idea what to do. Could someone give me some suggestions?

	1. The code runs extremely slow. I noticed that there’s only empty implementation of HeapTimer and CGActivityCallback by default. Will GC work without HeapTimer implementation? I tried to implement them with WTF::RunLoop::Timer, and it seems to be better. I’m no sure whether there are other unimplemented methods.
	2. The code frequently crashes (not always) at the line “RELEASE_ASSERT(!source.isNull());” in the constructor of class  FunctionExecutable. The stack is:
::WTFCrash() Assertions.cpp:337
JSC::FunctionExecutable::FunctionExecutable(JSC::VM&, JSC::SourceCode const&, JSC::UnlinkedFunctionExecutable*, unsigned int, unsigned int, unsigned int, unsigned int, JSC::Intrinsic) FunctionExecutable.cpp:48
JSC::FunctionExecutable::create(JSC::VM&, JSC::SourceCode const&, JSC::UnlinkedFunctionExecutable*, unsigned int, unsigned int, unsigned int, unsigned int, JSC::Intrinsic) FunctionExecutable.h:43
JSC::UnlinkedFunctionExecutable::link(JSC::VM&, JSC::SourceCode const&, std::optional<int>, JSC::Intrinsic) UnlinkedFunctionExecutable.cpp:162
JSC::CodeBlock::finishCreation(JSC::VM&, JSC::ScriptExecutable*, JSC::UnlinkedCodeBlock*, JSC::JSScope*) CodeBlock.cpp:1987
JSC::FunctionCodeBlock::create(JSC::VM*, JSC::FunctionExecutable*, JSC::UnlinkedFunctionCodeBlock*, JSC::JSScope*, WTF::PassRefPtr<JSC::SourceProvider>, unsigned int, unsigned int) FunctionCodeBlock.h:55
JSC::ScriptExecutable::newCodeBlockFor(JSC::CodeSpecializationKind, JSC::JSFunction*, JSC::JSScope*, JSC::JSObject*&) ScriptExecutable.cpp:240
JSC::ScriptExecutable::prepareForExecutionImpl(JSC::VM&, JSC::JSFunction*, JSC::JSScope*, JSC::CodeSpecializationKind, JSC::CodeBlock*&) ScriptExecutable.cpp:319
JSC::JSObject* JSC::ScriptExecutable::prepareForExecution<JSC::FunctionExecutable>(JSC::VM&, JSC::JSFunction*, JSC::JSScope*, JSC::CodeSpecializationKind, JSC::CodeBlock*&) CodeBlock.h:1101
JSC::Interpreter::executeCall(JSC::ExecState*, JSC::JSObject*, JSC::CallType, JSC::CallData const&, JSC::JSValue, JSC::ArgList const&) Interpreter.cpp:935
JSC::call(JSC::ExecState*, JSC::JSValue, JSC::CallType, JSC::CallData const&, JSC::JSValue, JSC::ArgList const&) CallData.cpp:39
JSC::profiledCall(JSC::ExecState*, JSC::ProfilingReason, JSC::JSValue, JSC::CallType, JSC::CallData const&, JSC::JSValue, JSC::ArgList const&) CallData.cpp:59
::JSObjectCallAsFunction(JSContextRef, JSObjectRef, JSObjectRef, size_t, const JSValueRef *, JSValueRef *) JSObjectRef.cpp:541

my code is as below which works well on mac and iOS:
JSValueRef loadModule(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
{
    JSStringRef message = nullptr;
    do {
        if ((argumentCount == 4 || argumentCount == 5) && JSValueIsString(ctx, arguments[0]))
        {
            std::string path = jsval_to_value<std::string>(ctx, arguments[0]);
            JSObjectRef moduleObj = JSValueToObject(ctx, arguments[3], exception);
            if (*exception)
                break;
            auto body = String::stringWithContentsOfFile(path.c_str());
            if (!body)
            {
                message = JSStringCreateWithUTF8CString(StringUtil::Format("cannot load file %s", path.c_str()).c_str());
                break;
            }
            if (body->length() == 0)
            {
                return nullptr;
            }
            JSStringRef pathUrl = JSStringCreateWithUTF8CString(path.c_str());
            JSStringRef bodyStr = JSStringCreateWithUTF8CString(body->c_str());
            
            size_t extraParams = 0;
            JSPropertyNameArrayRef nameArr = nullptr;
            JSObjectRef extra = nullptr;
            if (argumentCount == 5)
            {
                extra = JSValueToObject(ctx, arguments[4], nullptr);
                if (extra)
                {
                    nameArr = JSObjectCopyPropertyNames(ctx, extra);
                    extraParams = JSPropertyNameArrayGetCount(nameArr);
                }
            }
            JSValueRef args[3 + extraParams];
            args[0] = arguments[1];
            args[1] = arguments[2];
            args[2] = arguments[3];
            JSStringRef params[3 + extraParams];
            params[0] = JSStringCreateWithUTF8CString("require");
            params[1] = JSStringCreateWithUTF8CString("exports");
            params[2] = JSStringCreateWithUTF8CString("module");
            if (extra && extraParams > 0)
            {
                for (int i = 0; i < extraParams; ++i)
                {
                    params[3 + i] = JSPropertyNameArrayGetNameAtIndex(nameArr, i);
                    args[3 + i] = JSObjectGetProperty(ctx, extra, params[3 + i], nullptr);
                }
            }
            JSObjectRef func = JSObjectMakeFunction(ctx, NULL, (unsigned)extraParams + 3, params, bodyStr, pathUrl, 1, exception);
            JSStringRelease(pathUrl);
            JSStringRelease(bodyStr);
            JSStringRelease(params[0]);
            JSStringRelease(params[1]);
            JSStringRelease(params[2]);
            if (nameArr)
                JSPropertyNameArrayRelease(nameArr);
            
            if (*exception) break;
            JSObjectCallAsFunction(ctx, func, moduleObj, extraParams + 3, args, exception);
            return nullptr;
        }
    } while(0);
    
    if (!*exception)
    {
        if (!message)
            message = JSStringCreateWithUTF8CString("invalid arguments for loadModule");
        JSValueRef value = JSValueMakeString(ctx, message);
        *exception = JSObjectMakeError(ctx, 1, &value, nullptr);
        JSStringRelease(message);
    }
    return nullptr;
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.webkit.org/pipermail/jsc-dev/attachments/20161228/c25a8c9e/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 1789 bytes
Desc: not available
URL: <https://lists.webkit.org/pipermail/jsc-dev/attachments/20161228/c25a8c9e/attachment-0001.p7s>


More information about the jsc-dev mailing list