本文整理汇总了C++中JSDOMGlobalObject::scriptExecutionContext方法的典型用法代码示例。如果您正苦于以下问题:C++ JSDOMGlobalObject::scriptExecutionContext方法的具体用法?C++ JSDOMGlobalObject::scriptExecutionContext怎么用?C++ JSDOMGlobalObject::scriptExecutionContext使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JSDOMGlobalObject
的用法示例。
在下文中一共展示了JSDOMGlobalObject::scriptExecutionContext方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: resetInternalsObject
void resetInternalsObject(JSContextRef context)
{
JSLock lock(SilenceAssertionsOnly);
ExecState* exec = toJS(context);
JSDOMGlobalObject* globalObject = static_cast<JSDOMGlobalObject*>(exec->lexicalGlobalObject());
Internals * internals = toInternals(globalObject->getDirect(exec->globalData(), Identifier(exec, Internals::internalsId)));
if (internals) {
ScriptExecutionContext* scriptContext = globalObject->scriptExecutionContext();
if (scriptContext->isDocument())
internals->reset(static_cast<Document*>(scriptContext));
}
}
示例2: reportException
void reportException(ExecState* exec, JSValue exception, CachedScript* cachedScript)
{
if (isTerminatedExecutionException(exception))
return;
Interpreter::ErrorHandlingMode mode(exec);
RefPtr<ScriptCallStack> callStack(createScriptCallStackFromException(exec, exception, ScriptCallStack::maxCallStackSizeToCapture));
exec->clearException();
exec->clearSupplementaryExceptionInfo();
JSDOMGlobalObject* globalObject = jsCast<JSDOMGlobalObject*>(exec->lexicalGlobalObject());
if (JSDOMWindow* window = jsDynamicCast<JSDOMWindow*>(globalObject)) {
if (!window->impl()->isCurrentlyDisplayedInFrame())
return;
}
int lineNumber = 0;
int columnNumber = 0;
String exceptionSourceURL;
if (callStack->size()) {
const ScriptCallFrame& frame = callStack->at(0);
lineNumber = frame.lineNumber();
columnNumber = frame.columnNumber();
exceptionSourceURL = frame.sourceURL();
} else {
// There may not be an exceptionStack for a <script> SyntaxError. Fallback to getting at least the line and sourceURL from the exception.
JSObject* exceptionObject = exception.toObject(exec);
JSValue lineValue = exceptionObject->getDirect(exec->vm(), Identifier(exec, "line"));
lineNumber = lineValue && lineValue.isNumber() ? int(lineValue.toNumber(exec)) : 0;
JSValue columnValue = exceptionObject->getDirect(exec->vm(), Identifier(exec, "column"));
columnNumber = columnValue && columnValue.isNumber() ? int(columnValue.toNumber(exec)) : 0;
JSValue sourceURLValue = exceptionObject->getDirect(exec->vm(), Identifier(exec, "sourceURL"));
exceptionSourceURL = sourceURLValue && sourceURLValue.isString() ? sourceURLValue.toString(exec)->value(exec) : ASCIILiteral("undefined");
}
String errorMessage;
if (ExceptionBase* exceptionBase = toExceptionBase(exception))
errorMessage = exceptionBase->message() + ": " + exceptionBase->description();
else {
// FIXME: <http://webkit.org/b/115087> Web Inspector: WebCore::reportException should not evaluate JavaScript handling exceptions
// If this is a custon exception object, call toString on it to try and get a nice string representation for the exception.
errorMessage = exception.toString(exec)->value(exec);
exec->clearException();
exec->clearSupplementaryExceptionInfo();
}
ScriptExecutionContext* scriptExecutionContext = globalObject->scriptExecutionContext();
scriptExecutionContext->reportException(errorMessage, lineNumber, columnNumber, exceptionSourceURL, callStack->size() ? callStack : 0, cachedScript);
}
示例3: reportException
void reportException(ExecState* exec, Exception* exception, CachedScript* cachedScript)
{
RELEASE_ASSERT(exec->vm().currentThreadIsHoldingAPILock());
if (isTerminatedExecutionException(exception))
return;
ErrorHandlingScope errorScope(exec->vm());
RefPtr<ScriptCallStack> callStack(createScriptCallStackFromException(exec, exception, ScriptCallStack::maxCallStackSizeToCapture));
exec->clearException();
exec->clearLastException();
JSDOMGlobalObject* globalObject = jsCast<JSDOMGlobalObject*>(exec->lexicalGlobalObject());
if (JSDOMWindow* window = jsDynamicCast<JSDOMWindow*>(globalObject)) {
if (!window->impl().isCurrentlyDisplayedInFrame())
return;
}
int lineNumber = 0;
int columnNumber = 0;
String exceptionSourceURL;
if (const ScriptCallFrame* callFrame = callStack->firstNonNativeCallFrame()) {
lineNumber = callFrame->lineNumber();
columnNumber = callFrame->columnNumber();
exceptionSourceURL = callFrame->sourceURL();
}
String errorMessage;
JSValue exceptionValue = exception->value();
if (ExceptionBase* exceptionBase = toExceptionBase(exceptionValue))
errorMessage = exceptionBase->message() + ": " + exceptionBase->description();
else {
// FIXME: <http://webkit.org/b/115087> Web Inspector: WebCore::reportException should not evaluate JavaScript handling exceptions
// If this is a custon exception object, call toString on it to try and get a nice string representation for the exception.
if (ErrorInstance* error = jsDynamicCast<ErrorInstance*>(exceptionValue))
errorMessage = error->sanitizedToString(exec);
else
errorMessage = exceptionValue.toString(exec)->value(exec);
// We need to clear any new exception that may be thrown in the toString() call above.
// reportException() is not supposed to be making new exceptions.
exec->clearException();
exec->clearLastException();
}
ScriptExecutionContext* scriptExecutionContext = globalObject->scriptExecutionContext();
scriptExecutionContext->reportException(errorMessage, lineNumber, columnNumber, exceptionSourceURL, callStack->size() ? callStack : 0, cachedScript);
}
示例4: handleEvent
void JSEventListener::handleEvent(Event* event, bool isWindowEvent)
{
JSLock lock(SilenceAssertionsOnly);
JSObject* jsFunction = this->jsFunction();
if (!jsFunction)
return;
JSDOMGlobalObject* globalObject = m_globalObject;
// Null check as clearGlobalObject() can clear this and we still get called back by
// xmlhttprequest objects. See http://bugs.webkit.org/show_bug.cgi?id=13275
// FIXME: Is this check still necessary? Requests are supposed to be stopped before clearGlobalObject() is called.
ASSERT(globalObject);
if (!globalObject)
return;
ScriptExecutionContext* scriptExecutionContext = globalObject->scriptExecutionContext();
if (!scriptExecutionContext)
return;
if (scriptExecutionContext->isDocument()) {
JSDOMWindow* window = static_cast<JSDOMWindow*>(globalObject);
Frame* frame = window->impl()->frame();
if (!frame)
return;
// The window must still be active in its frame. See <https://bugs.webkit.org/show_bug.cgi?id=21921>.
// FIXME: A better fix for this may be to change DOMWindow::frame() to not return a frame the detached window used to be in.
if (frame->domWindow() != window->impl())
return;
// FIXME: Is this check needed for other contexts?
ScriptController* script = frame->script();
if (!script->isEnabled() || script->isPaused())
return;
}
ExecState* exec = globalObject->globalExec();
JSValue handleEventFunction = jsFunction->get(exec, Identifier(exec, "handleEvent"));
CallData callData;
CallType callType = handleEventFunction.getCallData(callData);
if (callType == CallTypeNone) {
handleEventFunction = JSValue();
callType = jsFunction->getCallData(callData);
}
if (callType != CallTypeNone) {
ref();
MarkedArgumentBuffer args;
args.append(toJS(exec, globalObject, event));
Event* savedEvent = globalObject->currentEvent();
globalObject->setCurrentEvent(event);
// If this event handler is the first JavaScript to execute, then the
// dynamic global object should be set to the global object of the
// window in which the event occurred.
JSGlobalData* globalData = globalObject->globalData();
DynamicGlobalObjectScope globalObjectScope(exec, globalData->dynamicGlobalObject ? globalData->dynamicGlobalObject : globalObject);
JSValue retval;
if (handleEventFunction) {
globalObject->globalData()->timeoutChecker.start();
retval = call(exec, handleEventFunction, callType, callData, jsFunction, args);
} else {
JSValue thisValue;
if (isWindowEvent)
thisValue = globalObject->toThisObject(exec);
else
thisValue = toJS(exec, globalObject, event->currentTarget());
globalObject->globalData()->timeoutChecker.start();
retval = call(exec, jsFunction, callType, callData, thisValue, args);
}
globalObject->globalData()->timeoutChecker.stop();
globalObject->setCurrentEvent(savedEvent);
if (exec->hadException())
reportCurrentException(exec);
else {
if (!retval.isUndefinedOrNull() && event->storesResultAsString())
event->storeResult(retval.toString(exec));
if (m_isAttribute) {
bool retvalbool;
if (retval.getBoolean(retvalbool) && !retvalbool)
event->preventDefault();
}
}
if (scriptExecutionContext->isDocument())
Document::updateStyleForAllDocuments();
deref();
}
}