本文整理汇总了C++中JSGlobalObject类的典型用法代码示例。如果您正苦于以下问题:C++ JSGlobalObject类的具体用法?C++ JSGlobalObject怎么用?C++ JSGlobalObject使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了JSGlobalObject类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ASSERT
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);
}
示例2: codeBlockFor
PassRefPtr<FunctionCodeBlock> FunctionExecutable::produceCodeBlockFor(JSScope* scope, CodeSpecializationKind specializationKind, JSObject*& exception)
{
RefPtr<FunctionCodeBlock> alternative = codeBlockFor(specializationKind);
if (!!alternative) {
RefPtr<FunctionCodeBlock> result = adoptRef(new FunctionCodeBlock(CodeBlock::CopyParsedBlock, *codeBlockFor(specializationKind)));
result->setAlternative(alternative);
return result.release();
}
VM* vm = scope->vm();
JSGlobalObject* globalObject = scope->globalObject();
ParserError error;
DebuggerMode debuggerMode = globalObject->hasDebugger() ? DebuggerOn : DebuggerOff;
ProfilerMode profilerMode = globalObject->hasProfiler() ? ProfilerOn : ProfilerOff;
UnlinkedFunctionCodeBlock* unlinkedCodeBlock = m_unlinkedExecutable->codeBlockFor(*vm, m_source, specializationKind, debuggerMode, profilerMode, error);
recordParse(m_unlinkedExecutable->features(), m_unlinkedExecutable->hasCapturedVariables(), lineNo(), lastLine(), startColumn());
if (!unlinkedCodeBlock) {
exception = error.toErrorObject(globalObject, m_source);
return 0;
}
SourceProvider* provider = source().provider();
unsigned sourceOffset = source().startOffset();
unsigned startColumn = source().startColumn();
return adoptRef(new FunctionCodeBlock(this, unlinkedCodeBlock, scope, provider, sourceOffset, startColumn));
}
示例3: OBJECT_TO_JSVAL
JSBool JSJSGlobalObject::fromjs_isTimerValid(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) {
// get instance
JSGlobalObject *object = static_cast<JSGlobalObject *>(reinterpret_cast<JSScriptable *>(JS_GetPrivate(cx, obj)));
if (!object) {
JSScriptable::js_throwNullCallException(JSJSGlobalObject::classDescriptor.name, JSJSGlobalObject::functionTable[4].name);
return JS_FALSE;
}
// record context
object->js_setCurrentContext(cx);
// JSTimer *timer
JSObject *p0;
if (!JS_ValueToObject(cx, argv[0], &p0))
return JS_FALSE;
argv[0] = OBJECT_TO_JSVAL(p0);
JSTimer *p0o = NULL;
if (p0) {
JSScriptable *pobj = reinterpret_cast<JSScriptable*>(JS_GetPrivate(cx, p0));
if (!pobj) {
object->js_throwNullParamException(0, JSJSGlobalObject::functionTable[4].name, JSJSGlobalObject::classDescriptor.name);
return JS_FALSE;
}
p0o = static_cast<JSTimer *>(pobj->js_getInterface(JS_JSTimer_GUID));
if (!p0o) {
object->js_throwParamTypeException(0, JSJSTimer::classDescriptor.name, JSJSGlobalObject::functionTable[4].name, JSJSGlobalObject::classDescriptor.name);
return JS_FALSE;
}
}
// call method
ASSERT(object != NULL);
bool rv = object->isTimerValid(p0o);
// handle return value
*rval = BOOLEAN_TO_JSVAL(rv);
// success
return JS_TRUE;
}
示例4: recordParse
bool FunctionExecutable::compileForConstruct(ExecState*, ScopeChainNode* scopeChainNode)
{
JSGlobalData* globalData = scopeChainNode->globalData;
RefPtr<FunctionBodyNode> body = globalData->parser->parse<FunctionBodyNode>(globalData, 0, 0, m_source);
if (!body)
return false;
if (m_forceUsesArguments)
body->setUsesArguments();
body->finishParsing(m_parameters, m_name);
recordParse(body->features(), body->lineNo(), body->lastLine());
ScopeChain scopeChain(scopeChainNode);
JSGlobalObject* globalObject = scopeChain.globalObject();
ASSERT(!m_codeBlockForConstruct);
m_codeBlockForConstruct = new FunctionCodeBlock(this, FunctionCode, source().provider(), source().startOffset(), true);
OwnPtr<BytecodeGenerator> generator(new BytecodeGenerator(body.get(), globalObject->debugger(), scopeChain, m_codeBlockForConstruct->symbolTable(), m_codeBlockForConstruct));
generator->generate();
m_numParametersForConstruct = m_codeBlockForConstruct->m_numParameters;
ASSERT(m_numParametersForConstruct);
m_numVariables = m_codeBlockForConstruct->m_numVars;
m_symbolTable = m_codeBlockForConstruct->sharedSymbolTable();
body->destroyData();
return true;
}
示例5: 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 { };
}
示例6: jsNull
String Database::toJSON() const
{
JSGlobalObject* globalObject = JSGlobalObject::create(
m_vm, JSGlobalObject::createStructure(m_vm, jsNull()));
return JSONStringify(globalObject->globalExec(), toJS(globalObject->globalExec()), 0);
}
示例7: RELEASE_ASSERT
JSObject* ProgramExecutable::initializeGlobalProperties(VM& vm, CallFrame* callFrame, JSScope* scope)
{
RELEASE_ASSERT(scope);
JSGlobalObject* globalObject = scope->globalObject();
RELEASE_ASSERT(globalObject);
ASSERT(&globalObject->vm() == &vm);
JSObject* exception = 0;
UnlinkedProgramCodeBlock* unlinkedCodeBlock = globalObject->createProgramCodeBlock(callFrame, this, &exception);
if (exception)
return exception;
m_unlinkedProgramCodeBlock.set(vm, this, unlinkedCodeBlock);
BatchedTransitionOptimizer optimizer(vm, globalObject);
for (size_t i = 0, numberOfFunctions = unlinkedCodeBlock->numberOfFunctionDecls(); i < numberOfFunctions; ++i) {
UnlinkedFunctionExecutable* unlinkedFunctionExecutable = unlinkedCodeBlock->functionDecl(i);
ASSERT(!unlinkedFunctionExecutable->name().isEmpty());
globalObject->addFunction(callFrame, unlinkedFunctionExecutable->name());
if (vm.typeProfiler() || vm.controlFlowProfiler()) {
vm.functionHasExecutedCache()->insertUnexecutedRange(sourceID(),
unlinkedFunctionExecutable->typeProfilingStartOffset(),
unlinkedFunctionExecutable->typeProfilingEndOffset());
}
}
const VariableEnvironment& variableDeclarations = unlinkedCodeBlock->variableDeclarations();
for (auto& entry : variableDeclarations) {
ASSERT(entry.value.isVar());
globalObject->addVar(callFrame, Identifier::fromUid(&vm, entry.key.get()));
}
return 0;
}
示例8: jsTestNondeterministicNondeterministicSetterExceptionAttr
EncodedJSValue jsTestNondeterministicNondeterministicSetterExceptionAttr(ExecState* state, EncodedJSValue thisValue, PropertyName)
{
UNUSED_PARAM(state);
UNUSED_PARAM(thisValue);
JSValue decodedThisValue = JSValue::decode(thisValue);
auto* castedThis = jsDynamicCast<JSTestNondeterministic*>(decodedThisValue);
if (UNLIKELY(!castedThis)) {
return throwGetterTypeError(*state, "TestNondeterministic", "nondeterministicSetterExceptionAttr");
}
#if ENABLE(WEB_REPLAY)
JSGlobalObject* globalObject = state->lexicalGlobalObject();
InputCursor& cursor = globalObject->inputCursor();
static NeverDestroyed<const AtomicString> bindingName("TestNondeterministic.nondeterministicSetterExceptionAttr", AtomicString::ConstructFromLiteral);
if (cursor.isCapturing()) {
String memoizedResult = castedThis->wrapped().nondeterministicSetterExceptionAttr();
cursor.appendInput<MemoizedDOMResult<String>>(bindingName.get().string(), memoizedResult, 0);
JSValue result = jsStringWithCache(state, memoizedResult);
return JSValue::encode(result);
}
if (cursor.isReplaying()) {
String memoizedResult;
MemoizedDOMResultBase* input = cursor.fetchInput<MemoizedDOMResultBase>();
if (input && input->convertTo<String>(memoizedResult)) {
JSValue result = jsStringWithCache(state, memoizedResult);
return JSValue::encode(result);
}
}
#endif
auto& impl = castedThis->wrapped();
JSValue result = jsStringWithCache(state, impl.nondeterministicSetterExceptionAttr());
return JSValue::encode(result);
}
示例9: ASSERT
JSObject* ProgramExecutable::compileInternal(ExecState* exec, ScopeChainNode* scopeChainNode)
{
ASSERT(!m_programCodeBlock);
JSObject* exception = 0;
JSGlobalData* globalData = &exec->globalData();
JSGlobalObject* lexicalGlobalObject = exec->lexicalGlobalObject();
RefPtr<ProgramNode> programNode = globalData->parser->parse<ProgramNode>(lexicalGlobalObject, lexicalGlobalObject->debugger(), exec, m_source, 0, isStrictMode() ? JSParseStrict : JSParseNormal, &exception);
if (!programNode) {
ASSERT(exception);
return exception;
}
recordParse(programNode->features(), programNode->hasCapturedVariables(), programNode->lineNo(), programNode->lastLine());
ScopeChain scopeChain(scopeChainNode);
JSGlobalObject* globalObject = scopeChain.globalObject();
m_programCodeBlock = adoptPtr(new ProgramCodeBlock(this, GlobalCode, globalObject, source().provider()));
OwnPtr<BytecodeGenerator> generator(adoptPtr(new BytecodeGenerator(programNode.get(), scopeChain, &globalObject->symbolTable(), m_programCodeBlock.get())));
generator->generate();
programNode->destroyData();
#if ENABLE(JIT)
if (exec->globalData().canUseJIT()) {
m_jitCodeForCall = JIT::compile(scopeChainNode->globalData, m_programCodeBlock.get());
#if !ENABLE(OPCODE_SAMPLING)
if (!BytecodeGenerator::dumpsGeneratedCode())
m_programCodeBlock->discardBytecode();
#endif
}
#endif
return 0;
}
示例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: scopeChain
ExceptionInfo* FunctionExecutable::reparseExceptionInfo(JSGlobalData* globalData, ScopeChainNode* scopeChainNode, CodeBlock* codeBlock)
{
RefPtr<FunctionBodyNode> newFunctionBody = globalData->parser->parse<FunctionBodyNode>(globalData, 0, 0, m_source);
if (m_forceUsesArguments)
newFunctionBody->setUsesArguments();
newFunctionBody->finishParsing(m_parameters, m_name);
ScopeChain scopeChain(scopeChainNode);
JSGlobalObject* globalObject = scopeChain.globalObject();
OwnPtr<CodeBlock> newCodeBlock(new FunctionCodeBlock(this, FunctionCode, source().provider(), source().startOffset()));
globalData->functionCodeBlockBeingReparsed = newCodeBlock.get();
OwnPtr<BytecodeGenerator> generator(new BytecodeGenerator(newFunctionBody.get(), globalObject->debugger(), scopeChain, newCodeBlock->symbolTable(), newCodeBlock.get()));
generator->setRegeneratingForExceptionInfo(static_cast<FunctionCodeBlock*>(codeBlock));
generator->generate();
ASSERT(newCodeBlock->instructionCount() == codeBlock->instructionCount());
#if ENABLE(JIT)
JITCode newJITCode = JIT::compile(globalData, newCodeBlock.get());
ASSERT(newJITCode.size() == generatedJITCode().size());
#endif
globalData->functionCodeBlockBeingReparsed = 0;
return newCodeBlock->extractExceptionInfo();
}
示例12: jsTestNondeterministicNondeterministicWriteableAttr
EncodedJSValue jsTestNondeterministicNondeterministicWriteableAttr(ExecState* exec, JSObject* slotBase, EncodedJSValue thisValue, PropertyName)
{
UNUSED_PARAM(exec);
UNUSED_PARAM(slotBase);
UNUSED_PARAM(thisValue);
JSTestNondeterministic* castedThis = jsDynamicCast<JSTestNondeterministic*>(JSValue::decode(thisValue));
if (UNLIKELY(!castedThis)) {
if (jsDynamicCast<JSTestNondeterministicPrototype*>(slotBase))
return reportDeprecatedGetterError(*exec, "TestNondeterministic", "nondeterministicWriteableAttr");
return throwGetterTypeError(*exec, "TestNondeterministic", "nondeterministicWriteableAttr");
}
#if ENABLE(WEB_REPLAY)
JSGlobalObject* globalObject = exec->lexicalGlobalObject();
InputCursor& cursor = globalObject->inputCursor();
static NeverDestroyed<const AtomicString> bindingName("TestNondeterministic.nondeterministicWriteableAttr", AtomicString::ConstructFromLiteral);
if (cursor.isCapturing()) {
String memoizedResult = castedThis->impl().nondeterministicWriteableAttr();
cursor.appendInput<MemoizedDOMResult<String>>(bindingName.get().string(), memoizedResult, 0);
JSValue result = jsStringWithCache(exec, memoizedResult);
return JSValue::encode(result);
}
if (cursor.isReplaying()) {
String memoizedResult;
MemoizedDOMResultBase* input = cursor.fetchInput<MemoizedDOMResultBase>();
if (input && input->convertTo<String>(memoizedResult)) {
JSValue result = jsStringWithCache(exec, memoizedResult);
return JSValue::encode(result);
}
}
#endif
TestNondeterministic& impl = castedThis->impl();
JSValue result = jsStringWithCache(exec, impl.nondeterministicWriteableAttr());
return JSValue::encode(result);
}
示例13: constructFunction
// ECMA 15.3.2 The Function Constructor
JSObject* constructFunction(ExecState* exec, const ArgList& args, const Identifier& functionName, const UString& sourceURL, int lineNumber)
{
// Functions need to have a space following the opening { due to for web compatibility
// see https://bugs.webkit.org/show_bug.cgi?id=24350
// We also need \n before the closing } to handle // comments at the end of the last line
UString program;
if (args.isEmpty())
program = "(function() { \n})";
else if (args.size() == 1)
program = makeString("(function() { ", args.at(0).toString(exec), "\n})");
else {
StringBuilder builder;
builder.append("(function(");
builder.append(args.at(0).toString(exec));
for (size_t i = 1; i < args.size() - 1; i++) {
builder.append(",");
builder.append(args.at(i).toString(exec));
}
builder.append(") { ");
builder.append(args.at(args.size() - 1).toString(exec));
builder.append("\n})");
program = builder.build();
}
int errLine;
UString errMsg;
SourceCode source = makeSource(program, sourceURL, lineNumber);
RefPtr<FunctionExecutable> function = FunctionExecutable::fromGlobalCode(functionName, exec, exec->dynamicGlobalObject()->debugger(), source, &errLine, &errMsg);
if (!function)
return throwError(exec, SyntaxError, errMsg, errLine, source.provider()->asID(), source.provider()->url());
JSGlobalObject* globalObject = exec->lexicalGlobalObject();
ScopeChain scopeChain(globalObject, globalObject->globalData(), globalObject, exec->globalThisValue());
return new (exec) JSFunction(exec, function, scopeChain.node());
}
示例14: constructFunction
// ECMA 15.3.2 The Function Constructor
JSObject* constructFunction(ExecState* exec, const ArgList& args, const Identifier& functionName, const UString& sourceURL, int lineNumber)
{
UString program;
if (args.isEmpty())
program = "(function(){})";
else if (args.size() == 1)
program = "(function(){" + args.at(exec, 0)->toString(exec) + "})";
else {
program = "(function(" + args.at(exec, 0)->toString(exec);
for (size_t i = 1; i < args.size() - 1; i++)
program += "," + args.at(exec, i)->toString(exec);
program += "){" + args.at(exec, args.size() - 1)->toString(exec) + "})";
}
int errLine;
UString errMsg;
SourceCode source = makeSource(program, sourceURL, lineNumber);
RefPtr<ProgramNode> programNode = exec->globalData().parser->parse<ProgramNode>(exec, exec->dynamicGlobalObject()->debugger(), source, &errLine, &errMsg);
FunctionBodyNode* body = functionBody(programNode.get());
if (!body)
return throwError(exec, SyntaxError, errMsg, errLine, source.provider()->asID(), source.provider()->url());
JSGlobalObject* globalObject = exec->lexicalGlobalObject();
ScopeChain scopeChain(globalObject, globalObject->globalData(), exec->globalThisValue());
return new (exec) JSFunction(exec, functionName, body, scopeChain.node());
}
示例15: 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());
}