本文整理汇总了C++中JSGlobalObject::globalExec方法的典型用法代码示例。如果您正苦于以下问题:C++ JSGlobalObject::globalExec方法的具体用法?C++ JSGlobalObject::globalExec怎么用?C++ JSGlobalObject::globalExec使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JSGlobalObject
的用法示例。
在下文中一共展示了JSGlobalObject::globalExec方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: toJSON
String Database::toJSON() const
{
JSGlobalObject* globalObject = JSGlobalObject::create(
m_vm, JSGlobalObject::createStructure(m_vm, jsNull()));
return JSONStringify(globalObject->globalExec(), toJS(globalObject->globalExec()), 0);
}
示例2: JSGlobalContextCreateInGroup
JSGlobalContextRef JSGlobalContextCreateInGroup(JSContextGroupRef group, JSClassRef globalObjectClass)
{
initializeThreading();
RefPtr<VM> vm = group ? PassRefPtr<VM>(toJS(group)) : VM::createContextGroup();
JSLockHolder locker(vm.get());
if (!globalObjectClass) {
JSGlobalObject* globalObject = JSGlobalObject::create(*vm, JSGlobalObject::createStructure(*vm, jsNull()));
#if ENABLE(REMOTE_INSPECTOR)
if (JSRemoteInspectorGetInspectionEnabledByDefault())
globalObject->setRemoteDebuggingEnabled(true);
#endif
return JSGlobalContextRetain(toGlobalRef(globalObject->globalExec()));
}
JSGlobalObject* globalObject = JSCallbackObject<JSGlobalObject>::create(*vm, globalObjectClass, JSCallbackObject<JSGlobalObject>::createStructure(*vm, 0, jsNull()));
ExecState* exec = globalObject->globalExec();
JSValue prototype = globalObjectClass->prototype(exec);
if (!prototype)
prototype = jsNull();
globalObject->resetPrototype(*vm, prototype);
#if ENABLE(REMOTE_INSPECTOR)
if (JSRemoteInspectorGetInspectionEnabledByDefault())
globalObject->setRemoteDebuggingEnabled(true);
#endif
return JSGlobalContextRetain(toGlobalRef(exec));
}
示例3: toJSON
String Database::toJSON() const
{
auto scope = DECLARE_THROW_SCOPE(m_vm);
JSGlobalObject* globalObject = JSGlobalObject::create(
m_vm, JSGlobalObject::createStructure(m_vm, jsNull()));
auto value = toJS(globalObject->globalExec());
RETURN_IF_EXCEPTION(scope, String());
scope.release();
return JSONStringify(globalObject->globalExec(), value, 0);
}
示例4: functionRun
JSValue JSC_HOST_CALL functionRun(ExecState* exec, JSObject*, JSValue, const ArgList& args)
{
StopWatch stopWatch;
UString fileName = args.at(0).toString(exec);
Vector<char> script;
if (!fillBufferWithContentsOfFile(fileName, script))
return throwError(exec, GeneralError, "Could not open file.");
JSGlobalObject* globalObject = exec->lexicalGlobalObject();
stopWatch.start();
evaluate(globalObject->globalExec(), globalObject->globalScopeChain(), makeSource(script.data(), fileName));
stopWatch.stop();
return jsNumber(globalObject->globalExec(), stopWatch.getElapsedMS());
}
示例5: JSEvaluateScript
JSValueRef JSEvaluateScript(JSContextRef ctx, JSStringRef script, JSObjectRef thisObject, JSStringRef sourceURL, int startingLineNumber, JSValueRef* exception)
{
ExecState* exec = toJS(ctx);
exec->globalData().heap.registerThread();
JSLock lock(exec);
JSObject* jsThisObject = toJS(thisObject);
// evaluate sets "this" to the global object if it is NULL
JSGlobalObject* globalObject = exec->dynamicGlobalObject();
SourceCode source = makeSource(script->ustring(), sourceURL->ustring(), startingLineNumber);
Completion completion = evaluate(globalObject->globalExec(), globalObject->globalScopeChain(), source, jsThisObject);
if (completion.complType() == Throw) {
if (exception)
*exception = toRef(completion.value());
return 0;
}
if (completion.value())
return toRef(completion.value());
// happens, for example, when the only statement is an empty (';') statement
return toRef(jsUndefined());
}
示例6: doCallToJavaScript
EncodedJSValue doCallToJavaScript(void* executableAddress, ProtoCallFrame* protoCallFrame)
{
CodeBlock* codeBlock = protoCallFrame->codeBlock();
JSScope* scope = protoCallFrame->scope();
JSObject* callee = protoCallFrame->callee();
int argCountIncludingThis = protoCallFrame->argumentCountIncludingThis();
int argCount = protoCallFrame->argumentCount();
JSValue thisValue = protoCallFrame->thisValue();
JSStack& stack = scope->vm()->interpreter->stack();
CallFrame* newCallFrame = stack.pushFrame(codeBlock, scope, argCountIncludingThis, callee);
if (UNLIKELY(!newCallFrame)) {
JSGlobalObject* globalObject = scope->globalObject();
ExecState* exec = globalObject->globalExec();
return JSValue::encode(throwStackOverflowError(exec));
}
// Set the arguments for the callee:
newCallFrame->setThisValue(thisValue);
for (int i = 0; i < argCount; ++i)
newCallFrame->setArgument(i, protoCallFrame->argument(i));
JSValue result = execute(newCallFrame, executableAddress);
stack.popFrame(newCallFrame);
return JSValue::encode(result);
}
示例7: functionRun
JSValue* functionRun(ExecState* exec, JSObject*, JSValue*, const ArgList& args)
{
StopWatch stopWatch;
UString fileName = args.at(exec, 0)->toString(exec);
Vector<char> script;
if (!fillBufferWithContentsOfFile(fileName, script))
return throwError(exec, GeneralError, "Could not open file.");
JSGlobalObject* globalObject = exec->dynamicGlobalObject();
stopWatch.start();
Interpreter::evaluate(globalObject->globalExec(), globalObject->globalScopeChain(), fileName, 1, script.data());
stopWatch.stop();
return jsNumber(globalObject->globalExec(), stopWatch.getElapsedMS());
}
示例8: getRemoteObject
void InspectorHeapAgent::getRemoteObject(ErrorString& errorString, int heapObjectId, const String* optionalObjectGroup, RefPtr<Inspector::Protocol::Runtime::RemoteObject>& result)
{
// Prevent the cell from getting collected as we look it up.
VM& vm = m_environment.vm();
JSLockHolder lock(vm);
DeferGC deferGC(vm.heap);
unsigned heapObjectIdentifier = static_cast<unsigned>(heapObjectId);
const Optional<HeapSnapshotNode> optionalNode = nodeForHeapObjectIdentifier(errorString, heapObjectIdentifier);
if (!optionalNode)
return;
JSCell* cell = optionalNode->cell;
Structure* structure = cell->structure(m_environment.vm());
if (!structure) {
errorString = ASCIILiteral("Unable to get object details");
return;
}
JSGlobalObject* globalObject = structure->globalObject();
if (!globalObject) {
errorString = ASCIILiteral("Unable to get object details");
return;
}
InjectedScript injectedScript = m_injectedScriptManager.injectedScriptFor(globalObject->globalExec());
if (injectedScript.hasNoValue()) {
errorString = ASCIILiteral("Unable to get object details - InjectedScript");
return;
}
Deprecated::ScriptValue cellScriptValue(m_environment.vm(), JSValue(cell));
String objectGroup = optionalObjectGroup ? *optionalObjectGroup : String();
result = injectedScript.wrapObject(cellScriptValue, objectGroup, true);
}
示例9: parseRuleList
std::error_code parseRuleList(const String& rules, Vector<ContentExtensionRule>& ruleList)
{
#if CONTENT_EXTENSIONS_PERFORMANCE_REPORTING
double loadExtensionStartTime = monotonicallyIncreasingTime();
#endif
RefPtr<VM> vm = VM::create();
JSLockHolder locker(vm.get());
JSGlobalObject* globalObject = JSGlobalObject::create(*vm, JSGlobalObject::createStructure(*vm, jsNull()));
ExecState* exec = globalObject->globalExec();
auto error = loadEncodedRules(*exec, rules, ruleList);
vm = nullptr;
if (error)
return error;
if (ruleList.isEmpty())
return ContentExtensionError::JSONContainsNoRules;
#if CONTENT_EXTENSIONS_PERFORMANCE_REPORTING
double loadExtensionEndTime = monotonicallyIncreasingTime();
dataLogF("Time spent loading extension %f\n", (loadExtensionEndTime - loadExtensionStartTime));
#endif
return { };
}
示例10: JSEvaluateScriptInternal
JSValueRef JSEvaluateScriptInternal(const JSLockHolder&, ExecState* exec, JSContextRef ctx, JSObjectRef thisObject, const SourceCode& source, JSValueRef* exception)
{
UNUSED_PARAM(ctx);
JSObject* jsThisObject = toJS(thisObject);
// evaluate sets "this" to the global object if it is NULL
VM& vm = exec->vm();
JSGlobalObject* globalObject = vm.vmEntryGlobalObject(exec);
NakedPtr<Exception> evaluationException;
JSValue returnValue = profiledEvaluate(globalObject->globalExec(), ProfilingReason::API, source, jsThisObject, evaluationException);
if (evaluationException) {
if (exception)
*exception = toRef(exec, evaluationException->value());
#if ENABLE(REMOTE_INSPECTOR)
// FIXME: If we have a debugger attached we could learn about ParseError exceptions through
// ScriptDebugServer::sourceParsed and this path could produce a duplicate warning. The
// Debugger path is currently ignored by inspector.
// NOTE: If we don't have a debugger, this SourceCode will be forever lost to the inspector.
// We could stash it in the inspector in case an inspector is ever opened.
globalObject->inspectorController().reportAPIException(exec, evaluationException);
#endif
return nullptr;
}
if (returnValue)
return toRef(exec, returnValue);
// happens, for example, when the only statement is an empty (';') statement
return toRef(exec, jsUndefined());
}
示例11: JSEvaluateScript
JSValueRef JSEvaluateScript(JSContextRef ctx, JSStringRef script, JSObjectRef thisObject, JSStringRef sourceURL, int startingLineNumber, JSValueRef* exception)
{
if (!ctx) {
ASSERT_NOT_REACHED();
return 0;
}
ExecState* exec = toJS(ctx);
APIEntryShim entryShim(exec);
JSObject* jsThisObject = toJS(thisObject);
// evaluate sets "this" to the global object if it is NULL
JSGlobalObject* globalObject = exec->dynamicGlobalObject();
SourceCode source = makeSource(script->string(), sourceURL->string(), TextPosition(OrdinalNumber::fromOneBasedInt(startingLineNumber), OrdinalNumber::first()));
JSValue evaluationException;
JSValue returnValue = evaluate(globalObject->globalExec(), source, jsThisObject, &evaluationException);
if (evaluationException) {
if (exception)
*exception = toRef(exec, evaluationException);
return 0;
}
if (returnValue)
return toRef(exec, returnValue);
// happens, for example, when the only statement is an empty (';') statement
return toRef(exec, jsUndefined());
}
示例12: handleEvent
bool JSCustomSQLStatementErrorCallback::handleEvent(SQLTransaction* transaction, SQLError* error)
{
ASSERT(m_callback);
ASSERT(m_frame);
if (!m_frame->script()->isEnabled())
return true;
JSGlobalObject* globalObject = m_frame->script()->globalObject();
ExecState* exec = globalObject->globalExec();
KJS::JSLock lock;
JSValue* handleEventFunction = m_callback->get(exec, Identifier(exec, "handleEvent"));
CallData handleEventCallData;
CallType handleEventCallType = handleEventFunction->getCallData(handleEventCallData);
CallData callbackCallData;
CallType callbackCallType = CallTypeNone;
if (handleEventCallType == CallTypeNone) {
callbackCallType = m_callback->getCallData(callbackCallData);
if (callbackCallType == CallTypeNone) {
// FIXME: Should an exception be thrown here?
return true;
}
}
RefPtr<JSCustomSQLStatementErrorCallback> protect(this);
ArgList args;
args.append(toJS(exec, transaction));
args.append(toJS(exec, error));
JSValue* result;
globalObject->startTimeoutCheck();
if (handleEventCallType != CallTypeNone)
result = call(exec, handleEventFunction, handleEventCallType, handleEventCallData, m_callback, args);
else
result = call(exec, m_callback, callbackCallType, callbackCallData, m_callback, args);
globalObject->stopTimeoutCheck();
if (exec->hadException()) {
JSObject* exception = exec->exception()->toObject(exec);
String message = exception->get(exec, exec->propertyNames().message)->toString(exec);
int lineNumber = exception->get(exec, Identifier(exec, "line"))->toInt32(exec);
String sourceURL = exception->get(exec, Identifier(exec, "sourceURL"))->toString(exec);
m_frame->domWindow()->console()->addMessage(JSMessageSource, ErrorMessageLevel, message, lineNumber, sourceURL);
exec->clearException();
// The spec says:
// "If the error callback returns false, then move on to the next statement..."
// "Otherwise, the error callback did not return false, or there was no error callback"
// Therefore an exception and returning true are the same thing - so, return true on an exception
return true;
}
Document::updateDocumentsRendering();
return result->toBoolean(exec);
}
示例13: globalExec
ExecState* NPRuntimeObjectMap::globalExec() const
{
JSGlobalObject* globalObject = this->globalObject();
if (!globalObject)
return 0;
return globalObject->globalExec();
}
示例14: JSGlobalContextCreate
JSGlobalContextRef JSGlobalContextCreate(JSClassRef globalObjectClass)
{
initializeThreading();
#if OS(DARWIN)
// When running on Tiger or Leopard, or if the application was linked before JSGlobalContextCreate was changed
// to use a unique JSGlobalData, we use a shared one for compatibility.
#ifndef BUILDING_ON_LEOPARD
if (NSVersionOfLinkTimeLibrary("JavaScriptCore") <= webkitFirstVersionWithConcurrentGlobalContexts) {
#else
{
#endif
JSLock lock(LockForReal);
return JSGlobalContextCreateInGroup(toRef(&JSGlobalData::sharedInstance()), globalObjectClass);
}
#endif // OS(DARWIN)
return JSGlobalContextCreateInGroup(0, globalObjectClass);
}
JSGlobalContextRef JSGlobalContextCreateInGroup(JSContextGroupRef group, JSClassRef globalObjectClass)
{
initializeThreading();
JSLock lock(LockForReal);
RefPtr<JSGlobalData> globalData = group ? PassRefPtr<JSGlobalData>(toJS(group)) : JSGlobalData::createContextGroup(ThreadStackTypeSmall);
APIEntryShim entryShim(globalData.get(), false);
#if ENABLE(JSC_MULTIPLE_THREADS)
globalData->makeUsableFromMultipleThreads();
#endif
if (!globalObjectClass) {
JSGlobalObject* globalObject = JSGlobalObject::create(*globalData, JSGlobalObject::createStructure(*globalData, jsNull()));
return JSGlobalContextRetain(toGlobalRef(globalObject->globalExec()));
}
JSGlobalObject* globalObject = JSCallbackObject<JSGlobalObject>::create(*globalData, globalObjectClass, JSCallbackObject<JSGlobalObject>::createStructure(*globalData, 0, jsNull()));
ExecState* exec = globalObject->globalExec();
JSValue prototype = globalObjectClass->prototype(exec);
if (!prototype)
prototype = jsNull();
globalObject->resetPrototype(*globalData, prototype);
return JSGlobalContextRetain(toGlobalRef(exec));
}
示例15: willEvaluateScript
double InspectorScriptProfilerAgent::willEvaluateScript(JSGlobalObject& globalObject)
{
m_activeEvaluateScript = true;
if (m_enableLegacyProfiler)
LegacyProfiler::profiler()->startProfiling(globalObject.globalExec(), ASCIILiteral("ScriptProfiler"), m_environment.executionStopwatch());
return m_environment.executionStopwatch()->elapsedTime();
}