本文整理汇总了C++中JSFunction::setScope方法的典型用法代码示例。如果您正苦于以下问题:C++ JSFunction::setScope方法的具体用法?C++ JSFunction::setScope怎么用?C++ JSFunction::setScope使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JSFunction
的用法示例。
在下文中一共展示了JSFunction::setScope方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: initializeJSFunction
JSObject* JSLazyEventListener::initializeJSFunction(ScriptExecutionContext* executionContext) const
{
ASSERT(executionContext);
ASSERT(executionContext->isDocument());
if (!executionContext)
return 0;
Document* document = static_cast<Document*>(executionContext);
if (!document->frame())
return 0;
if (!document->contentSecurityPolicy()->allowInlineEventHandlers())
return 0;
ScriptController* script = document->frame()->script();
if (!script->canExecuteScripts(AboutToExecuteScript) || script->isPaused())
return 0;
JSDOMGlobalObject* globalObject = toJSDOMGlobalObject(executionContext, isolatedWorld());
if (!globalObject)
return 0;
ExecState* exec = globalObject->globalExec();
MarkedArgumentBuffer args;
args.append(jsNontrivialString(exec, stringToUString(m_eventParameterName)));
args.append(jsString(exec, m_code));
JSObject* jsFunction = constructFunctionSkippingEvalEnabledCheck(exec, exec->lexicalGlobalObject(), args, Identifier(exec, stringToUString(m_functionName)), stringToUString(m_sourceURL), m_position); // FIXME: is globalExec ok?
if (exec->hadException()) {
reportCurrentException(exec);
exec->clearException();
return 0;
}
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.
JSLock lock(SilenceAssertionsOnly);
// FIXME: Should pass the global object associated with the node
setWrapper(exec->globalData(), 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(exec->globalData(), jsCast<JSNode*>(wrapper())->pushEventHandlerScope(exec, listenerAsFunction->scope()));
}
// Since we only parse once, there's no need to keep data used for parsing around anymore.
m_functionName = String();
m_code = String();
m_eventParameterName = String();
m_sourceURL = String();
return jsFunction;
}
示例2: parseCode
void JSLazyEventListener::parseCode() const
{
if (m_parsed)
return;
if (m_globalObject->scriptExecutionContext()->isDocument()) {
JSDOMWindow* window = static_cast<JSDOMWindow*>(m_globalObject);
Frame* frame = window->impl()->frame();
if (!frame)
return;
// FIXME: Is this check needed for non-Document contexts?
ScriptController* script = frame->script();
if (!script->isEnabled() || script->isPaused())
return;
}
m_parsed = true;
ExecState* exec = m_globalObject->globalExec();
MarkedArgumentBuffer args;
UString sourceURL(m_globalObject->scriptExecutionContext()->url().string());
args.append(jsNontrivialString(exec, m_eventParameterName));
args.append(jsString(exec, m_code));
// FIXME: Passing the document's URL to construct is not always correct, since this event listener might
// have been added with setAttribute from a script, and we should pass String() in that case.
m_jsFunction = constructFunction(exec, args, Identifier(exec, m_functionName), sourceURL, m_lineNumber); // FIXME: is globalExec ok?
JSFunction* listenerAsFunction = static_cast<JSFunction*>(m_jsFunction);
if (exec->hadException()) {
exec->clearException();
// failed to parse, so let's just make this listener a no-op
m_jsFunction = 0;
} else if (m_originalNode) {
// Add the event's home element to the scope
// (and the document, and the form - see JSHTMLElement::eventHandlerScope)
ScopeChain scope = listenerAsFunction->scope();
JSValue thisObj = toJS(exec, m_originalNode);
if (thisObj.isObject()) {
static_cast<JSNode*>(asObject(thisObj))->pushEventHandlerScope(exec, scope);
listenerAsFunction->setScope(scope);
}
}
// Since we only parse once, there's no need to keep data used for parsing around anymore.
m_functionName = String();
m_code = String();
m_eventParameterName = String();
}
示例3: parseCode
void JSLazyEventListener::parseCode() const
{
if (m_parsed)
return;
m_parsed = true;
Frame* frame = window()->impl()->frame();
if (frame && frame->script()->isEnabled()) {
ExecState* exec = window()->globalExec();
JSLock lock(false);
ArgList args;
UString sourceURL(frame->loader()->url().string());
args.append(eventParameterName());
args.append(jsString(exec, m_code));
// FIXME: Passing the document's URL to construct is not always correct, since this event listener might
// have been added with setAttribute from a script, and we should pass String() in that case.
m_listener = constructFunction(exec, args, Identifier(exec, m_functionName), sourceURL, m_lineNumber); // FIXME: is globalExec ok?
JSFunction* listenerAsFunction = static_cast<JSFunction*>(m_listener.get());
if (exec->hadException()) {
exec->clearException();
// failed to parse, so let's just make this listener a no-op
m_listener = 0;
} else if (m_originalNode) {
// Add the event's home element to the scope
// (and the document, and the form - see JSHTMLElement::eventHandlerScope)
ScopeChain scope = listenerAsFunction->scope();
JSValue* thisObj = toJS(exec, m_originalNode);
if (thisObj->isObject()) {
static_cast<JSEventTargetNode*>(thisObj)->pushEventHandlerScope(exec, scope);
listenerAsFunction->setScope(scope);
}
}
}
// no more need to keep the unparsed code around
m_functionName = String();
m_code = String();
if (m_listener) {
JSDOMWindow::ListenersMap& listeners = isHTMLEventListener()
? window()->jsHTMLEventListeners() : window()->jsEventListeners();
listeners.set(m_listener, const_cast<JSLazyEventListener*>(this));
}
}
示例4: operationNewFunctionExpression
JSCell* DFG_OPERATION operationNewFunctionExpression(ExecState* exec, JSCell* functionExecutableAsCell)
{
ASSERT(functionExecutableAsCell->inherits(&FunctionExecutable::s_info));
FunctionExecutable* functionExecutable =
static_cast<FunctionExecutable*>(functionExecutableAsCell);
JSFunction *function = functionExecutable->make(exec, exec->scopeChain());
if (!functionExecutable->name().isNull()) {
JSStaticScopeObject* functionScopeObject =
JSStaticScopeObject::create(
exec, functionExecutable->name(), function, ReadOnly | DontDelete);
function->setScope(exec->globalData(), function->scope()->push(functionScopeObject));
}
return function;
}
示例5: parseCode
void JSLazyEventListener::parseCode(ScriptExecutionContext* executionContext) const
{
ASSERT(executionContext);
ASSERT(executionContext->isDocument());
if (!executionContext)
return;
if (m_parsed)
return;
Frame* frame = static_cast<Document*>(executionContext)->frame();
if (!frame)
return;
ScriptController* scriptController = frame->script();
if (!scriptController->isEnabled())
return;
JSDOMGlobalObject* globalObject = toJSDOMGlobalObject(executionContext);
if (!globalObject)
return;
// Ensure that 'node' has a JavaScript wrapper to mark the event listener we're creating.
if (m_originalNode) {
JSLock lock(SilenceAssertionsOnly);
// FIXME: Should pass the global object associated with the node
toJS(globalObject->globalExec(), globalObject, m_originalNode);
}
if (executionContext->isDocument()) {
JSDOMWindow* window = static_cast<JSDOMWindow*>(globalObject);
Frame* frame = window->impl()->frame();
if (!frame)
return;
// FIXME: Is this check needed for non-Document contexts?
ScriptController* script = frame->script();
if (!script->isEnabled() || script->isPaused())
return;
}
m_parsed = true;
ExecState* exec = globalObject->globalExec();
MarkedArgumentBuffer args;
args.append(jsNontrivialString(exec, m_eventParameterName));
args.append(jsString(exec, m_code));
m_jsFunction = constructFunction(exec, args, Identifier(exec, m_functionName), m_sourceURL, m_lineNumber); // FIXME: is globalExec ok?
JSFunction* listenerAsFunction = static_cast<JSFunction*>(m_jsFunction);
if (exec->hadException()) {
exec->clearException();
// failed to parse, so let's just make this listener a no-op
m_jsFunction = 0;
} else if (m_originalNode) {
// Add the event's home element to the scope
// (and the document, and the form - see JSHTMLElement::eventHandlerScope)
ScopeChain scope = listenerAsFunction->scope();
JSValue thisObj = toJS(exec, globalObject, m_originalNode);
if (thisObj.isObject()) {
static_cast<JSNode*>(asObject(thisObj))->pushEventHandlerScope(exec, scope);
listenerAsFunction->setScope(scope);
}
}
// Since we only parse once, there's no need to keep data used for parsing around anymore.
m_functionName = String();
m_code = String();
m_eventParameterName = String();
m_sourceURL = String();
}
示例6: 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;
}
示例7: initializeJSFunction
JSObject* JSLazyEventListener::initializeJSFunction(ScriptExecutionContext* executionContext) const
{
ASSERT(executionContext);
ASSERT(executionContext->isDocument());
if (!executionContext)
return 0;
Frame* frame = static_cast<Document*>(executionContext)->frame();
if (!frame)
return 0;
ScriptController* scriptController = frame->script();
if (!scriptController->canExecuteScripts(AboutToExecuteScript))
return 0;
JSDOMGlobalObject* globalObject = toJSDOMGlobalObject(executionContext, isolatedWorld());
if (!globalObject)
return 0;
if (executionContext->isDocument()) {
JSDOMWindow* window = static_cast<JSDOMWindow*>(globalObject);
Frame* frame = window->impl()->frame();
if (!frame)
return 0;
// FIXME: Is this check needed for non-Document contexts?
ScriptController* script = frame->script();
if (!script->canExecuteScripts(AboutToExecuteScript) || script->isPaused())
return 0;
}
ExecState* exec = globalObject->globalExec();
MarkedArgumentBuffer args;
args.append(jsNontrivialString(exec, stringToUString(m_eventParameterName)));
args.append(jsString(exec, m_code));
JSObject* jsFunction = constructFunction(exec, args, Identifier(exec, stringToUString(m_functionName)), stringToUString(m_sourceURL), m_lineNumber); // FIXME: is globalExec ok?
if (exec->hadException()) {
exec->clearException();
return 0;
}
JSFunction* listenerAsFunction = static_cast<JSFunction*>(jsFunction);
if (m_originalNode) {
if (!wrapper()) {
// Ensure that 'node' has a JavaScript wrapper to mark the event listener we're creating.
JSLock lock(SilenceAssertionsOnly);
// FIXME: Should pass the global object associated with the node
setWrapper(asObject(toJS(globalObject->globalExec(), globalObject, m_originalNode)));
}
// Add the event's home element to the scope
// (and the document, and the form - see JSHTMLElement::eventHandlerScope)
ScopeChain scope = listenerAsFunction->scope();
static_cast<JSNode*>(wrapper())->pushEventHandlerScope(exec, scope);
listenerAsFunction->setScope(scope);
}
// Since we only parse once, there's no need to keep data used for parsing around anymore.
m_functionName = String();
m_code = String();
m_eventParameterName = String();
m_sourceURL = String();
return jsFunction;
}