Example #1
0
void InspectorTimelineAgent::didReceiveResourceResponse(unsigned long identifier, const ResourceResponse& response)
{
    ScriptObject record = TimelineRecordFactory::createGenericRecord(m_frontend, currentTimeInMilliseconds());
    record.set("data", TimelineRecordFactory::createResourceReceiveResponseData(m_frontend, identifier, response));
    record.set("type", ResourceReceiveResponseTimelineRecordType);
    m_frontend->addRecordToTimeline(record);
}
JSValue JSHTMLCanvasElement::getContext(ExecState* exec)
{
    HTMLCanvasElement* canvas = static_cast<HTMLCanvasElement*>(impl());
    const String& contextId = exec->argument(0).toString(exec)->value(exec);
    
    RefPtr<CanvasContextAttributes> attrs;
#if ENABLE(WEBGL)
    if (HTMLCanvasElement::is3dType(contextId)) {
        get3DContextAttributes(exec, attrs);
        if (exec->hadException())
            return jsUndefined();
    }
#endif
    
    CanvasRenderingContext* context = canvas->getContext(contextId, attrs.get());
    if (!context)
        return jsNull();
    JSValue jsValue = toJS(exec, globalObject(), WTF::getPtr(context));
    if (InspectorInstrumentation::canvasAgentEnabled(canvas->document())) {
        ScriptObject contextObject(exec, jsValue.getObject());
        ScriptObject wrapped;
        if (context->is2d())
            wrapped = InspectorInstrumentation::wrapCanvas2DRenderingContextForInstrumentation(canvas->document(), contextObject);
#if ENABLE(WEBGL)
        else if (context->is3d())
            wrapped = InspectorInstrumentation::wrapWebGLRenderingContextForInstrumentation(canvas->document(), contextObject);
#endif
        if (!wrapped.hasNoValue())
            return wrapped.jsValue();
    }
    return jsValue;
}
Example #3
0
        Atom nextValue(int i)
        {
            if (count == 0)
            {
                return undefinedAtom;
            }

            Sampler * const sampler = script->core()->get_sampler();
            if (sampler == NULL || sampleBufferId != sampler->getSampleBufferId())
            {
                count = 0;
                return undefinedAtom;
            }

            (void) i;
            Sample s;
            sampler->readSample(cursor, s);
            count--;
            ScriptObject* sam = SamplerScript::makeSample(script, cf, s);
            if(!sam) {
                count = 0;
                return undefinedAtom;
            }
            return sam->atom();
        }
Example #4
0
    Atom VectorBaseObject::filter(ScriptObject *callback, Atom thisObject)
    {
        AvmCore* core = this->core();
        VectorBaseObject *r = newVector();

        if (!callback)
            return r->atom();

        ScriptObject *d = this;
        uint32 len = m_length;

        for (uint32 i = 0, k = 0; i < len; i++)
        {
            // If thisObject is null, the call function will substitute the global object
            // args are modified in place by callee
            Atom element = d->getUintProperty(i);
            Atom args[4] = {
                thisObject,
                element,
                core->uintToAtom(i), // index
                this->atom()
            };
            Atom result = callback->call(3, args);
            if (result == trueAtom)
                r->setUintProperty(k++, element);
        }

        return r->atom();
    }
    /**
     * Array.prototype.reverse()
	 * TRANSFERABLE: Needs to support generic objects as well as Array objects
     */
	/*static*/ Atom ArrayClass::generic_reverse(Toplevel* toplevel, Atom thisAtom)
    {
        ArrayObject *a = isArray(toplevel, thisAtom);
	
		if (a && (a->isSimpleDense()))
		{
			a->m_denseArr.reverse();
			return thisAtom;
		}

		// generic object version
		if (!AvmCore::isObject(thisAtom))
			return thisAtom;

		ScriptObject *d = AvmCore::atomToScriptObject(thisAtom);
		uint32 j = getLengthHelper(toplevel, d);

		uint32 i = 0;
		if (j)
			j--;

		while (i < j) {
			Atom frontAtom = d->getUintProperty(i);
			Atom backAtom  = d->getUintProperty(j);

			d->setUintProperty(i++, backAtom);
			d->setUintProperty(j--, frontAtom);
		}

		return thisAtom;
	}
	/**
     * Array.prototype.pop()
	 * TRANSFERABLE: Needs to support generic objects as well as Array objects
     */
	/*static*/ Atom ArrayClass::generic_pop(Toplevel* toplevel, Atom thisAtom)
    {
        ArrayObject *a = isArray(toplevel, thisAtom);

		if (a)
			return a->pop();

		if (!AvmCore::isObject(thisAtom))
			return undefinedAtom;

		// Different than Rhino (because of delete) but matches 262.pdf
		ScriptObject *d = AvmCore::atomToScriptObject(thisAtom);
		uint32 len = getLengthHelper(toplevel, d);
		if (!len)
		{
			setLengthHelper(toplevel, d, 0);
			return undefinedAtom;
		}
		else
		{
			Atom outAtom = d->getUintProperty (len-1); 
			d->delUintProperty (len - 1);
			setLengthHelper(toplevel, d, len - 1);
			return outAtom;
		}
    }
Example #7
0
    /**
        15.2.4.5 Object.prototype.hasOwnProperty (V)
        When the hasOwnProperty method is called with argument V, the following steps are taken:
        1. Let O be this object.
        2. Call ToString(V).
        3. If O doesn't have a property with the name given by Result(2), return false.
        4. Return true.
        NOTE Unlike [[HasProperty]] (section 8.6.2.4), this method does not consider objects in the prototype chain.
     */
    bool ObjectClass::_hasOwnProperty(Atom thisAtom, Stringp name)
    {
        AvmCore* core = this->core();
        name = name ? core->internString(name) : (Stringp)core->knull;

        Traitsp t = NULL;
        switch (atomKind(thisAtom))
        {
            case kObjectType:
            {
                // ISSUE should this look in traits and dynamic vars, or just dynamic vars.
                ScriptObject* obj = AvmCore::atomToScriptObject(thisAtom);
                // TODO
                // The change below is important as otherwise we will throw error in a call to hasAtomProperty for ByteArrayObject.
                // This gets us back to the behaviour which we had in Marlin.
                // A bugzilla bug [ 562224 ] has been created to address this issue more cleanly in near future
                return obj->traits()->getTraitsBindings()->findBinding(name, core->findPublicNamespace()) != BIND_NONE ||
                    obj->hasStringProperty(name);
            }
            case kNamespaceType:
            case kStringType:
            case kBooleanType:
            case kDoubleType:
            case kIntptrType:
                t = toplevel()->toTraits(thisAtom);
                break;
            default:
                return false;
        }
        // NOTE use caller's public namespace
        return t->getTraitsBindings()->findBinding(name, core->findPublicNamespace()) != BIND_NONE;
    }
ScriptObject TimelineRecordFactory::createEvaluateScriptData(InspectorFrontend* frontend, const String& url, double lineNumber) 
{
    ScriptObject data = frontend->newScriptObject();
    data.set("url", url);
    data.set("lineNumber", lineNumber);
    return data;
}
Example #9
0
File: ffi.cpp Project: miviwi/DD
void *LuaScript::registerCFunc(void *context, const char *name, void *func)
{
  DECL_STATE(L, context);

  auto func_wrapper = [](lua_State *L) -> int
  {
    ScriptContext::CFunc func = (ScriptContext::CFunc)lua_touserdata(L, lua_upvalueindex(1));

    int argc = lua_gettop(L);
    Vector<ScriptObject> args(argc);
    args.resize(argc);

    for(int i = argc; i; i--) {
      void *ref = OBJECT(luaL_ref(L, LUA_REGISTRYINDEX));
      args[i-1] = ScriptObject(L, ref);
    }

    ScriptObject ret = func(args, kwargs_stub);

    if(!ret.isBound()) return 0;

    PUSH_REF(L, ret.object);
    return 1;
  };

  lua_pushlightuserdata(L, func);
  lua_pushcclosure(L, func_wrapper, 1);

  if(name) {
    lua_pushvalue(L, -1);
    lua_setglobal(L, name);
  }

  return OBJECT(luaL_ref(L, LUA_REGISTRYINDEX));
}
void InspectorTimelineAgent::didFinishLoadingResource(unsigned long identifier, bool didFail)
{
    ScriptObject record = TimelineRecordFactory::createGenericRecord(m_frontend, currentTimeInMilliseconds());
    record.set("data", TimelineRecordFactory::createResourceFinishData(m_frontend, identifier, didFail));
    record.set("type", ResourceFinishTimelineRecordType);
    m_frontend->addRecordToTimeline(record);
}
ScriptObject TimelineRecordFactory::createParseHTMLData(InspectorFrontend* frontend, unsigned int length, unsigned int startLine)
{
    ScriptObject data = frontend->newScriptObject();
    data.set("length", length);
    data.set("startLine", startLine);
    return data;
}
	Atom VectorBaseObject::filter(ScriptObject *callback, Atom thisObject)
	{
		AvmCore* core = this->core();
		VectorBaseObject *r = newVector();

		if (!callback)
			return r->atom();

		ScriptObject *d = this;
		uint32 len = m_length;

		// If thisObject is null, the call function will substitute the global object 
		Atom args[4] = { thisObject, nullObjectAtom, nullObjectAtom, this->atom() };

		for (uint32 i = 0, k = 0; i < len; i++)
		{
			args[1] = d->getUintProperty (i); // element
			args[2] = core->uintToAtom (i); // index

			Atom result = callback->call(3, args);

			if (result == trueAtom)
			{
				r->setUintProperty (k++, args[1]);
			}
		}

		return r->atom();
	}
ScriptObject TimelineRecordFactory::createXHRReadyStateChangeData(InspectorFrontend* frontend, const String& url, int readyState)
{
    ScriptObject data = frontend->newScriptObject();
    data.set("url", url);
    data.set("readyState", readyState);
    return data;
}
ScriptObject TimelineRecordFactory::createFunctionCallData(InspectorFrontend* frontend, const String& scriptName, int scriptLine)
{
    ScriptObject data = frontend->newScriptObject();
    data.set("scriptName", scriptName);
    data.set("scriptLine", scriptLine);
    return data;
}
ScriptObject TimelineRecordFactory::createResourceFinishData(InspectorFrontend* frontend, unsigned long identifier, bool didFail)
{
    ScriptObject data = frontend->newScriptObject();
    data.set("identifier", identifier);
    data.set("didFail", didFail);
    return data;
}
	/**
		15.2.4.5 Object.prototype.hasOwnProperty (V)
		When the hasOwnProperty method is called with argument V, the following steps are taken:
		1. Let O be this object.
		2. Call ToString(V).
		3. If O doesn’t have a property with the name given by Result(2), return false.
		4. Return true.
		NOTE Unlike [[HasProperty]] (section 8.6.2.4), this method does not consider objects in the prototype chain.
     */
	bool ObjectClass::_hasOwnProperty(Atom thisAtom, Stringp name)
	{
		AvmCore* core = this->core();
		name = name ? core->internString(name) : (Stringp)core->knull;

		Traitsp t = NULL;
		switch (atomKind(thisAtom))
		{
			case kObjectType:
			{
				// ISSUE should this look in traits and dynamic vars, or just dynamic vars.
				ScriptObject* obj = AvmCore::atomToScriptObject(thisAtom);
				if (obj->hasStringProperty(name))
					return true;
				t = obj->traits();
				break;
			}
			case kNamespaceType:
			case kStringType:
			case kBooleanType:
			case kDoubleType:
			case kIntegerType:
				t = toplevel()->toTraits(thisAtom);
				break;
			default:
				return false;
		}
		return t->getTraitsBindings()->findBinding(name, core->publicNamespace) != BIND_NONE;
	}
Example #17
0
void ScriptCallArgumentHandler::appendArgument(const ScriptObject& argument)
{
    if (argument.scriptState() != m_exec) {
        ASSERT_NOT_REACHED();
        return;
    }
    m_arguments.append(argument.jsObject());
}
ScriptObject TimelineRecordFactory::createTimerInstallData(InspectorFrontend* frontend, int timerId, int timeout, bool singleShot)
{
    ScriptObject data = frontend->newScriptObject();
    data.set("timerId", timerId);
    data.set("timeout", timeout);
    data.set("singleShot", singleShot);
    return data;
}
Example #19
0
ScriptObject DOMDispatchTimelineItem::convertToScriptObject(InspectorFrontend* frontend)
{
    ScriptObject selfObj = TimelineItem::convertToScriptObject(frontend);
    ScriptObject dataObj = frontend->newScriptObject();
    dataObj.set("type", m_eventType);
    selfObj.set("data", dataObj);
    return selfObj;
}
void InspectorTimelineAgent::willSendResourceRequest(unsigned long identifier, bool isMainResource,
    const ResourceRequest& request)
{
    ScriptObject record = TimelineRecordFactory::createGenericRecord(m_frontend, currentTimeInMilliseconds());
    record.set("data", TimelineRecordFactory::createResourceSendRequestData(m_frontend, identifier, isMainResource, request));
    record.set("type", ResourceSendRequestTimelineRecordType);
    m_frontend->addRecordToTimeline(record);
}
ScriptObject TimelineRecordFactory::createResourceReceiveResponseData(InspectorFrontend* frontend, unsigned long identifier, const ResourceResponse& response)
{
    ScriptObject data = frontend->newScriptObject();
    data.set("identifier", identifier);
    data.set("statusCode", response.httpStatusCode());
    data.set("mimeType", response.mimeType());
    data.set("expectedContentLength", response.expectedContentLength());
    return data;
}
ScriptObject TimelineRecordFactory::createResourceSendRequestData(InspectorFrontend* frontend, unsigned long identifier, bool isMainResource, const ResourceRequest& request)
{
    ScriptObject data = frontend->newScriptObject();
    data.set("identifier", identifier);
    data.set("url", request.url().string());
    data.set("requestMethod", request.httpMethod());
    data.set("isMainResource", isMainResource);
    return data;
}
ScriptObject TimelineRecordFactory::createPaintData(InspectorFrontend* frontend, const IntRect& rect)
{
    ScriptObject data = frontend->newScriptObject();
    data.set("x", rect.x());
    data.set("y", rect.y());
    data.set("width", rect.width());
    data.set("height", rect.height());
    return data;
}
static PassRefPtr<InspectorObject> scriptToInspectorObject(ScriptObject scriptObject)
{
    if (scriptObject.hasNoValue())
        return 0;
    RefPtr<InspectorValue> value = scriptObject.toInspectorValue(scriptObject.scriptState());
    if (!value)
        return 0;
    return value->asObject();
}
ScriptObject* needPrivileges(QScriptEngine *engine, const QString& fn, const QString& args, bool write = true){
	ScriptObject* sc = qobject_cast<ScriptObject*>(engine->globalObject().toQObject());
	REQUIRE_RET(sc, 0);
	if (write) {
		if (!sc->needWritePrivileges(fn, args)) return 0;
	} else {
		if (!sc->needReadPrivileges(fn, args)) return 0;
	}
	return sc;
}
Example #26
0
bool ScriptArray::set(unsigned index, const ScriptObject& value)
{
    if (value.scriptState() != m_scriptState) {
        ASSERT_NOT_REACHED();
        return false;
    }
    ScriptScope scope(m_scriptState);
    v8Object()->Set(v8::Integer::New(index), value.v8Value());
    return scope.success();
}
ScriptObject TimelineRecordFactory::createGenericRecord(InspectorFrontend* frontend, double startTime)
{
    ScriptObject record = frontend->newScriptObject();
    record.set("startTime", startTime);

    ScriptArray stackTrace;
    if (ScriptCallStack::stackTrace(5, frontend->scriptState(), stackTrace))
        record.set("stackTrace", stackTrace);
    return record;
}
Example #28
0
bool ScriptObject::set(const char* name, const ScriptObject& value)
{
    if (value.scriptState() != m_scriptState) {
        ASSERT_NOT_REACHED();
        return false;
    }
    JSLock lock(SilenceAssertionsOnly);
    PutPropertySlot slot;
    jsObject()->put(m_scriptState, Identifier(m_scriptState, name), value.jsObject(), slot);
    return handleException(m_scriptState);
}
Example #29
0
InjectedScriptCanvasModule InspectorCanvasAgent::injectedScriptCanvasModule(ErrorString* errorString, const ScriptObject& scriptObject)
{
    if (!checkIsEnabled(errorString))
        return InjectedScriptCanvasModule();
    if (scriptObject.hasNoValue()) {
        ASSERT_NOT_REACHED();
        *errorString = "Internal error: original ScriptObject has no value";
        return InjectedScriptCanvasModule();
    }
    return injectedScriptCanvasModule(errorString, scriptObject.scriptState());
}
Example #30
0
void ScriptObject::LogAll()
{
	OutputLog( "ScriptObject.LogAll output: \n" );
	for( int i = 0; i < object_array()->count(); i++ )
	{
		ScriptObject *object = ( *object_array() )( i );
		if( object )
		{
			OutputLog( "%s\n", object->GetFullName() );
		}
	}
}