本文整理汇总了C++中JSDOMGlobalObject::vm方法的典型用法代码示例。如果您正苦于以下问题:C++ JSDOMGlobalObject::vm方法的具体用法?C++ JSDOMGlobalObject::vm怎么用?C++ JSDOMGlobalObject::vm使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JSDOMGlobalObject
的用法示例。
在下文中一共展示了JSDOMGlobalObject::vm方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: createWrapper
JSC::JSValue createWrapper(JSDOMGlobalObject& globalObject, NodeList& nodeList)
{
// FIXME: Adopt reportExtraMemoryVisited, and switch to reportExtraMemoryAllocated.
// https://bugs.webkit.org/show_bug.cgi?id=142595
globalObject.vm().heap.deprecatedReportExtraMemory(nodeList.memoryCost());
return createNewWrapper<JSNodeList>(&globalObject, &nodeList);
}
示例2: handleEvent
void JSErrorHandler::handleEvent(ScriptExecutionContext* scriptExecutionContext, Event* event)
{
if (!is<ErrorEvent>(*event))
return JSEventListener::handleEvent(scriptExecutionContext, event);
ASSERT(scriptExecutionContext);
if (!scriptExecutionContext)
return;
ErrorEvent& errorEvent = downcast<ErrorEvent>(*event);
JSLockHolder lock(scriptExecutionContext->vm());
JSObject* jsFunction = this->jsFunction(scriptExecutionContext);
if (!jsFunction)
return;
JSDOMGlobalObject* globalObject = toJSDOMGlobalObject(scriptExecutionContext, isolatedWorld());
if (!globalObject)
return;
ExecState* exec = globalObject->globalExec();
CallData callData;
CallType callType = jsFunction->methodTable()->getCallData(jsFunction, callData);
if (callType != CallTypeNone) {
Ref<JSErrorHandler> protectedctor(*this);
Event* savedEvent = globalObject->currentEvent();
globalObject->setCurrentEvent(event);
MarkedArgumentBuffer args;
args.append(jsStringWithCache(exec, errorEvent.message()));
args.append(jsStringWithCache(exec, errorEvent.filename()));
args.append(jsNumber(errorEvent.lineno()));
args.append(jsNumber(errorEvent.colno()));
VM& vm = globalObject->vm();
VMEntryScope entryScope(vm, vm.entryScope ? vm.entryScope->globalObject() : globalObject);
NakedPtr<Exception> exception;
JSValue returnValue = scriptExecutionContext->isDocument()
? JSMainThreadExecState::call(exec, jsFunction, callType, callData, globalObject, args, exception)
: JSC::call(exec, jsFunction, callType, callData, globalObject, args, exception);
globalObject->setCurrentEvent(savedEvent);
if (exception)
reportException(exec, exception);
else {
if (returnValue.isTrue())
event->preventDefault();
}
}
}
示例3: handleEvent
void JSErrorHandler::handleEvent(ScriptExecutionContext* scriptExecutionContext, Event* event)
{
if (!event->hasInterface(eventNames().interfaceForErrorEvent))
return JSEventListener::handleEvent(scriptExecutionContext, event);
ASSERT(scriptExecutionContext);
if (!scriptExecutionContext)
return;
ErrorEvent* errorEvent = static_cast<ErrorEvent*>(event);
JSLockHolder lock(scriptExecutionContext->vm());
JSObject* jsFunction = this->jsFunction(scriptExecutionContext);
if (!jsFunction)
return;
JSDOMGlobalObject* globalObject = toJSDOMGlobalObject(scriptExecutionContext, isolatedWorld());
if (!globalObject)
return;
ExecState* exec = globalObject->globalExec();
CallData callData;
CallType callType = jsFunction->methodTable()->getCallData(jsFunction, callData);
if (callType != CallTypeNone) {
RefPtr<JSErrorHandler> protectedctor(this);
Event* savedEvent = globalObject->currentEvent();
globalObject->setCurrentEvent(event);
MarkedArgumentBuffer args;
args.append(jsStringWithCache(exec, errorEvent->message()));
args.append(jsStringWithCache(exec, errorEvent->filename()));
args.append(jsNumber(errorEvent->lineno()));
args.append(jsNumber(errorEvent->colno()));
VM& vm = globalObject->vm();
DynamicGlobalObjectScope globalObjectScope(vm, vm.dynamicGlobalObject ? vm.dynamicGlobalObject : globalObject);
JSValue returnValue = scriptExecutionContext->isDocument()
? JSMainThreadExecState::call(exec, jsFunction, callType, callData, globalObject, args)
: JSC::call(exec, jsFunction, callType, callData, globalObject, args);
globalObject->setCurrentEvent(savedEvent);
if (exec->hadException())
reportCurrentException(exec);
else {
if (returnValue.isTrue())
event->preventDefault();
}
}
}
示例4: handleEvent
void JSEventListener::handleEvent(ScriptExecutionContext* scriptExecutionContext, Event* event)
{
ASSERT(scriptExecutionContext);
if (!scriptExecutionContext || scriptExecutionContext->isJSExecutionForbidden())
return;
JSLockHolder lock(scriptExecutionContext->vm());
JSObject* jsFunction = this->jsFunction(scriptExecutionContext);
if (!jsFunction)
return;
JSDOMGlobalObject* globalObject = toJSDOMGlobalObject(scriptExecutionContext, *m_isolatedWorld);
if (!globalObject)
return;
if (scriptExecutionContext->isDocument()) {
JSDOMWindow* window = jsCast<JSDOMWindow*>(globalObject);
if (!window->impl().isCurrentlyDisplayedInFrame())
return;
// FIXME: Is this check needed for other contexts?
ScriptController& script = window->impl().frame()->script();
if (!script.canExecuteScripts(AboutToExecuteScript) || script.isPaused())
return;
}
ExecState* exec = globalObject->globalExec();
JSValue handleEventFunction = jsFunction;
CallData callData;
CallType callType = getCallData(handleEventFunction, callData);
// If jsFunction is not actually a function, see if it implements the EventListener interface and use that
if (callType == CallTypeNone) {
handleEventFunction = jsFunction->get(exec, Identifier::fromString(exec, "handleEvent"));
callType = getCallData(handleEventFunction, callData);
}
if (callType != CallTypeNone) {
Ref<JSEventListener> protect(*this);
MarkedArgumentBuffer args;
args.append(toJS(exec, globalObject, event));
Event* savedEvent = globalObject->currentEvent();
globalObject->setCurrentEvent(event);
VM& vm = globalObject->vm();
VMEntryScope entryScope(vm, vm.entryScope ? vm.entryScope->globalObject() : globalObject);
InspectorInstrumentationCookie cookie = JSMainThreadExecState::instrumentFunctionCall(scriptExecutionContext, callType, callData);
JSValue thisValue = handleEventFunction == jsFunction ? toJS(exec, globalObject, event->currentTarget()) : jsFunction;
NakedPtr<Exception> exception;
JSValue retval = scriptExecutionContext->isDocument()
? JSMainThreadExecState::call(exec, handleEventFunction, callType, callData, thisValue, args, exception)
: JSC::call(exec, handleEventFunction, callType, callData, thisValue, args, exception);
InspectorInstrumentation::didCallFunction(cookie, scriptExecutionContext);
globalObject->setCurrentEvent(savedEvent);
if (is<WorkerGlobalScope>(*scriptExecutionContext)) {
bool terminatorCausedException = (exec->hadException() && isTerminatedExecutionException(exec->exception()));
if (terminatorCausedException || (vm.watchdog && vm.watchdog->didFire()))
downcast<WorkerGlobalScope>(*scriptExecutionContext).script()->forbidExecution();
}
if (exception) {
event->target()->uncaughtExceptionInEventHandler();
reportException(exec, exception);
} else {
if (!retval.isUndefinedOrNull() && is<BeforeUnloadEvent>(*event))
downcast<BeforeUnloadEvent>(*event).setReturnValue(retval.toString(exec)->value(exec));
if (m_isAttribute) {
if (retval.isFalse())
event->preventDefault();
}
}
}
}
示例5: initializeJSFunction
JSObject* JSLazyEventListener::initializeJSFunction(ScriptExecutionContext* executionContext) const
{
ASSERT(is<Document>(executionContext));
if (!executionContext)
return nullptr;
ASSERT(!m_code.isNull());
ASSERT(!m_eventParameterName.isNull());
if (m_code.isNull() || m_eventParameterName.isNull())
return nullptr;
Document& document = downcast<Document>(*executionContext);
if (!document.frame())
return nullptr;
if (!document.contentSecurityPolicy()->allowInlineEventHandlers(m_sourceURL, m_sourcePosition.m_line))
return nullptr;
ScriptController& script = document.frame()->script();
if (!script.canExecuteScripts(AboutToExecuteScript) || script.isPaused())
return nullptr;
JSDOMGlobalObject* globalObject = toJSDOMGlobalObject(executionContext, isolatedWorld());
if (!globalObject)
return nullptr;
VM& vm = globalObject->vm();
JSLockHolder lock(vm);
auto scope = DECLARE_CATCH_SCOPE(vm);
ExecState* exec = globalObject->globalExec();
MarkedArgumentBuffer args;
args.append(jsNontrivialString(exec, m_eventParameterName));
args.append(jsStringWithCache(exec, m_code));
// We want all errors to refer back to the line on which our attribute was
// declared, regardless of any newlines in our JavaScript source text.
int overrideLineNumber = m_sourcePosition.m_line.oneBasedInt();
JSObject* jsFunction = constructFunctionSkippingEvalEnabledCheck(
exec, exec->lexicalGlobalObject(), args, Identifier::fromString(exec, m_functionName),
m_sourceURL, m_sourcePosition, overrideLineNumber);
if (UNLIKELY(scope.exception())) {
reportCurrentException(exec);
scope.clearException();
return nullptr;
}
JSFunction* listenerAsFunction = jsCast<JSFunction*>(jsFunction);
if (m_originalNode) {
if (!wrapper()) {
// Ensure that 'node' has a JavaScript wrapper to mark the event listener we're creating.
// FIXME: Should pass the global object associated with the node
setWrapper(vm, asObject(toJS(exec, globalObject, *m_originalNode)));
}
// Add the event's home element to the scope
// (and the document, and the form - see JSHTMLElement::eventHandlerScope)
listenerAsFunction->setScope(vm, jsCast<JSNode*>(wrapper())->pushEventHandlerScope(exec, listenerAsFunction->scope()));
}
return jsFunction;
}
示例6: createWrapper
JSC::JSValue createWrapper(JSDOMGlobalObject& globalObject, NodeList& nodeList)
{
globalObject.vm().heap.reportExtraMemoryCost(nodeList.memoryCost());
return createNewWrapper<JSNodeList>(&globalObject, &nodeList);
}