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); }
JSValueRef JSObjectCallAsFunction(JSContextRef ctx, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) { ExecState* exec = toJS(ctx); APIEntryShim entryShim(exec); JSObject* jsObject = toJS(object); JSObject* jsThisObject = toJS(thisObject); if (!jsThisObject) jsThisObject = exec->globalThisValue(); MarkedArgumentBuffer argList; for (size_t i = 0; i < argumentCount; i++) argList.append(toJS(exec, arguments[i])); CallData callData; CallType callType = jsObject->methodTable()->getCallData(jsObject, callData); if (callType == CallTypeNone) return 0; JSValueRef result = toRef(exec, call(exec, jsObject, callType, callData, jsThisObject, argList)); if (exec->hadException()) { if (exception) *exception = toRef(exec, exec->exception()); exec->clearException(); result = 0; } return result; }
bool JSValueIsInstanceOfConstructor(JSContextRef ctx, JSValueRef value, JSObjectRef constructor, JSValueRef* exception) { if (!ctx) { ASSERT_NOT_REACHED(); return false; } ExecState* exec = toJS(ctx); JSLockHolder locker(exec); JSValue jsValue = toJS(exec, value); JSObject* jsConstructor = toJS(constructor); if (!jsConstructor->structure()->typeInfo().implementsHasInstance()) return false; bool result = jsConstructor->hasInstance(exec, jsValue); // false if an exception is thrown if (exec->hadException()) { JSValue exceptionValue = exec->exception(); if (exception) *exception = toRef(exec, exceptionValue); exec->clearException(); #if ENABLE(REMOTE_INSPECTOR) exec->vmEntryGlobalObject()->inspectorController().reportAPIException(exec, exceptionValue); #endif } return result; }
JSObjectRef JSObjectCallAsConstructor(JSContextRef ctx, JSObjectRef object, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) { ExecState* exec = toJS(ctx); JSLockHolder locker(exec); if (!object) return 0; JSObject* jsObject = toJS(object); ConstructData constructData; ConstructType constructType = jsObject->methodTable()->getConstructData(jsObject, constructData); if (constructType == ConstructTypeNone) return 0; MarkedArgumentBuffer argList; for (size_t i = 0; i < argumentCount; i++) argList.append(toJS(exec, arguments[i])); JSObjectRef result = toRef(construct(exec, jsObject, constructType, constructData, argList)); if (exec->hadException()) { JSValue exceptionValue = exec->exception(); if (exception) *exception = toRef(exec, exceptionValue); exec->clearException(); #if ENABLE(REMOTE_INSPECTOR) exec->vmEntryGlobalObject()->inspectorController().reportAPIException(exec, exceptionValue); #endif result = 0; } return result; }
JSObjectRef JSObjectMakeArray(JSContextRef ctx, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) { ExecState* exec = toJS(ctx); exec->globalData().heap.registerThread(); JSLock lock(exec); JSObject* result; if (argumentCount) { ArgList argList; for (size_t i = 0; i < argumentCount; ++i) argList.append(toJS(arguments[i])); result = constructArray(exec, argList); } else result = constructEmptyArray(exec); if (exec->hadException()) { if (exception) *exception = toRef(exec->exception()); exec->clearException(); result = 0; } return toRef(result); }
JSObjectRef JSObjectMakeRegExp(JSContextRef ctx, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) { if (!ctx) { ASSERT_NOT_REACHED(); return 0; } ExecState* exec = toJS(ctx); JSLockHolder locker(exec); MarkedArgumentBuffer argList; for (size_t i = 0; i < argumentCount; ++i) argList.append(toJS(exec, arguments[i])); JSObject* result = constructRegExp(exec, exec->lexicalGlobalObject(), argList); if (exec->hadException()) { JSValue exceptionValue = exec->exception(); if (exception) *exception = toRef(exec, exceptionValue); exec->clearException(); #if ENABLE(REMOTE_INSPECTOR) exec->vmEntryGlobalObject()->inspectorController().reportAPIException(exec, exceptionValue); #endif result = 0; } return toRef(result); }
void JSObjectSetProperty(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef value, JSPropertyAttributes attributes, JSValueRef* exception) { if (!ctx) { ASSERT_NOT_REACHED(); return; } ExecState* exec = toJS(ctx); JSLockHolder locker(exec); JSObject* jsObject = toJS(object); Identifier name(propertyName->identifier(&exec->vm())); JSValue jsValue = toJS(exec, value); if (attributes && !jsObject->hasProperty(exec, name)) { PropertyDescriptor desc(jsValue, attributes); jsObject->methodTable()->defineOwnProperty(jsObject, exec, name, desc, false); } else { PutPropertySlot slot(jsObject); jsObject->methodTable()->put(jsObject, exec, name, jsValue, slot); } if (exec->hadException()) { JSValue exceptionValue = exec->exception(); if (exception) *exception = toRef(exec, exceptionValue); exec->clearException(); #if ENABLE(REMOTE_INSPECTOR) exec->vmEntryGlobalObject()->inspectorController().reportAPIException(exec, exceptionValue); #endif } }
JSObjectRef JSObjectCallAsConstructor(JSContextRef ctx, JSObjectRef object, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) { ExecState* exec = toJS(ctx); exec->globalData().heap->registerThread(); JSLock lock(exec); JSObject* jsObject = toJS(object); ConstructData constructData; ConstructType constructType = jsObject->getConstructData(constructData); if (constructType == ConstructTypeNone) return 0; ArgList argList; for (size_t i = 0; i < argumentCount; i++) argList.append(toJS(arguments[i])); JSObjectRef result = toRef(construct(exec, jsObject, constructType, constructData, argList)); if (exec->hadException()) { if (exception) *exception = toRef(exec->exception()); exec->clearException(); result = 0; } return result; }
JSObjectRef JSObjectMakeError(JSContextRef ctx, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) { if (!ctx) { ASSERT_NOT_REACHED(); return 0; } ExecState* exec = toJS(ctx); JSLockHolder locker(exec); JSValue message = argumentCount ? toJS(exec, arguments[0]) : jsUndefined(); Structure* errorStructure = exec->lexicalGlobalObject()->errorStructure(); JSObject* result = ErrorInstance::create(exec, errorStructure, message); if (exec->hadException()) { JSValue exceptionValue = exec->exception(); if (exception) *exception = toRef(exec, exceptionValue); exec->clearException(); #if ENABLE(REMOTE_INSPECTOR) exec->vmEntryGlobalObject()->inspectorController().reportAPIException(exec, exceptionValue); #endif result = 0; } return toRef(result); }
JSObjectRef JSObjectMakeFunction(JSContextRef ctx, JSStringRef name, unsigned parameterCount, const JSStringRef parameterNames[], JSStringRef body, JSStringRef sourceURL, int startingLineNumber, JSValueRef* exception) { if (!ctx) { ASSERT_NOT_REACHED(); return 0; } ExecState* exec = toJS(ctx); APIEntryShim entryShim(exec); Identifier nameID = name ? name->identifier(&exec->vm()) : Identifier(exec, "anonymous"); MarkedArgumentBuffer args; for (unsigned i = 0; i < parameterCount; i++) args.append(jsString(exec, parameterNames[i]->string())); args.append(jsString(exec, body->string())); JSObject* result = constructFunction(exec, exec->lexicalGlobalObject(), args, nameID, sourceURL->string(), TextPosition(OrdinalNumber::fromOneBasedInt(startingLineNumber), OrdinalNumber::first())); if (exec->hadException()) { if (exception) *exception = toRef(exec, exec->exception()); exec->clearException(); result = 0; } return toRef(result); }
JSObjectRef JSObjectMakeArray(JSContextRef ctx, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) { if (!ctx) { ASSERT_NOT_REACHED(); return 0; } ExecState* exec = toJS(ctx); APIEntryShim entryShim(exec); JSObject* result; if (argumentCount) { MarkedArgumentBuffer argList; for (size_t i = 0; i < argumentCount; ++i) argList.append(toJS(exec, arguments[i])); result = constructArray(exec, static_cast<ArrayAllocationProfile*>(0), argList); } else result = constructEmptyArray(exec, 0); if (exec->hadException()) { if (exception) *exception = toRef(exec, exec->exception()); exec->clearException(); result = 0; } return toRef(result); }
void JSObjectSetProperty(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef value, JSPropertyAttributes attributes, JSValueRef* exception) { if (!ctx) { ASSERT_NOT_REACHED(); return; } ExecState* exec = toJS(ctx); APIEntryShim entryShim(exec); JSObject* jsObject = toJS(object); Identifier name(propertyName->identifier(&exec->vm())); JSValue jsValue = toJS(exec, value); if (attributes && !jsObject->hasProperty(exec, name)) jsObject->methodTable()->putDirectVirtual(jsObject, exec, name, jsValue, attributes); else { PutPropertySlot slot; jsObject->methodTable()->put(jsObject, exec, name, jsValue, slot); } if (exec->hadException()) { if (exception) *exception = toRef(exec, exec->exception()); exec->clearException(); } }
void NamespaceJS::fireOnload() { if (m_onload) { AJOAGlobalObject* globalObject = OAGlobalObject::sharedInstance()->wrapper(); ASSERT(globalObject); ExecState* exec = globalObject->globalExec(); AJLock lock(exec); AJObject* callback = m_onload->optObject(); ASSERT(callback); CallData callData; CallType callType = callback->getCallData(callData); if (callType != CallTypeNone) { MarkedArgumentBuffer args; AJ::call(exec, callback, callType, callData, globalObject, args); if (exec->hadException()) reportAJException(exec, exec->exception()); } else oa_error("Invalid call type for JS.onload: %d", callType); } }
void KJSDebugWin::slotEval() { // Work out which execution state to use. If we're currently in a debugging session, // use the current context - otherwise, use the global execution state from the interpreter // corresponding to the currently displayed source file. ExecState *exec; Object thisobj; if(m_execStates.isEmpty()) { if(m_sourceSel->currentItem() < 0) return; SourceFile *sourceFile = m_sourceSelFiles.at(m_sourceSel->currentItem()); if(!sourceFile->interpreter) return; exec = sourceFile->interpreter->globalExec(); thisobj = exec->interpreter()->globalObject(); } else { exec = m_execStates.top(); thisobj = exec->context().thisValue(); } // Evaluate the js code from m_evalEdit UString code(m_evalEdit->code()); QString msg; KJSCPUGuard guard; guard.start(); Interpreter *interp = exec->interpreter(); Object obj = Object::dynamicCast(interp->globalObject().get(exec, "eval")); List args; args.append(String(code)); m_evalDepth++; Value retval = obj.call(exec, thisobj, args); m_evalDepth--; guard.stop(); // Print the return value or exception message to the console if(exec->hadException()) { Value exc = exec->exception(); exec->clearException(); msg = "Exception: " + exc.toString(interp->globalExec()).qstring(); } else { msg = retval.toString(interp->globalExec()).qstring(); } m_evalEdit->insert(msg + "\n"); updateContextList(); }
JSValue* WebScriptCallFrame::valueByEvaluatingJavaScriptFromString(String script) { #if 0 ExecState* state = m_state; JSGlobalObject* globObj = state->dynamicGlobalObject(); // find "eval" JSObject* eval = 0; if (state->scopeNode()) { // "eval" won't work without context (i.e. at global scope) JSValue* v = globObj->get(state, "eval"); if (v->isObject() && static_cast<JSObject*>(v)->implementsCall()) eval = static_cast<JSObject*>(v); else // no "eval" - fallback operates on global exec state state = globObj->globalExec(); } JSValue* savedException = state->exception(); state->clearException(); UString code(script.utf8().data()); // evaluate JSValue* scriptExecutionResult; if (eval) { List args; args.append(jsString(code)); scriptExecutionResult = eval->call(state, 0, args); } else // no "eval", or no context (i.e. global scope) - use global fallback scriptExecutionResult = Interpreter::evaluate(state, UString(), 0, code.data(), code.size(), globObj).value(); if (state->hadException()) scriptExecutionResult = state->exception(); // (may be redundant depending on which eval path was used) state->setException(savedException); return scriptExecutionResult; #else return jsNull(); #endif }
void JSObjectSetPropertyAtIndex(JSContextRef ctx, JSObjectRef object, unsigned propertyIndex, JSValueRef value, JSValueRef* exception) { JSLock lock; ExecState* exec = toJS(ctx); JSObject* jsObject = toJS(object); JSValue* jsValue = toJS(value); jsObject->put(exec, propertyIndex, jsValue); if (exec->hadException()) { if (exception) *exception = toRef(exec->exception()); exec->clearException(); } }
JSValueRef JSObjectGetPropertyAtIndex(JSContextRef ctx, JSObjectRef object, unsigned propertyIndex, JSValueRef* exception) { JSLock lock; ExecState* exec = toJS(ctx); JSObject* jsObject = toJS(object); JSValue* jsValue = jsObject->get(exec, propertyIndex); if (exec->hadException()) { if (exception) *exception = toRef(exec->exception()); exec->clearException(); } return toRef(jsValue); }
JSValueRef SerializedScriptValue::deserialize(JSContextRef destinationContext, JSValueRef* exception, MessagePortArray* messagePorts) { ExecState* exec = toJS(destinationContext); APIEntryShim entryShim(exec); JSValue value = deserialize(exec, exec->lexicalGlobalObject(), messagePorts); if (exec->hadException()) { if (exception) *exception = toRef(exec, exec->exception()); exec->clearException(); return 0; } ASSERT(value); return toRef(exec, value); }
bool JSObjectDeleteProperty(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception) { ExecState* exec = toJS(ctx); APIEntryShim entryShim(exec); JSObject* jsObject = toJS(object); bool result = jsObject->methodTable()->deleteProperty(jsObject, exec, propertyName->identifier(&exec->globalData())); if (exec->hadException()) { if (exception) *exception = toRef(exec, exec->exception()); exec->clearException(); } return result; }
void JSObjectSetPropertyAtIndex(JSContextRef ctx, JSObjectRef object, unsigned propertyIndex, JSValueRef value, JSValueRef* exception) { ExecState* exec = toJS(ctx); APIEntryShim entryShim(exec); JSObject* jsObject = toJS(object); JSValue jsValue = toJS(exec, value); jsObject->methodTable()->putByIndex(jsObject, exec, propertyIndex, jsValue, false); if (exec->hadException()) { if (exception) *exception = toRef(exec, exec->exception()); exec->clearException(); } }
JSValueRef JSObjectGetProperty(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception) { ExecState* exec = toJS(ctx); APIEntryShim entryShim(exec); JSObject* jsObject = toJS(object); JSValue jsValue = jsObject->get(exec, propertyName->identifier(&exec->globalData())); if (exec->hadException()) { if (exception) *exception = toRef(exec, exec->exception()); exec->clearException(); } return toRef(exec, jsValue); }
bool JSObjectDeleteProperty(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception) { JSLock lock; ExecState* exec = toJS(ctx); JSObject* jsObject = toJS(object); UString::Rep* nameRep = toJS(propertyName); bool result = jsObject->deleteProperty(exec, Identifier(exec, nameRep)); if (exec->hadException()) { if (exception) *exception = toRef(exec->exception()); exec->clearException(); } return result; }
bool JSValueIsEqual(JSContextRef ctx, JSValueRef a, JSValueRef b, JSValueRef* exception) { JSLock lock; ExecState* exec = toJS(ctx); JSValue* jsA = toJS(a); JSValue* jsB = toJS(b); bool result = equal(exec, jsA, jsB); // false if an exception is thrown if (exec->hadException()) { if (exception) *exception = toRef(exec->exception()); exec->clearException(); } return result; }
JSValueRef JSObjectGetProperty(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception) { JSLock lock; ExecState* exec = toJS(ctx); JSObject* jsObject = toJS(object); UString::Rep* nameRep = toJS(propertyName); JSValue* jsValue = jsObject->get(exec, Identifier(exec, nameRep)); if (exec->hadException()) { if (exception) *exception = toRef(exec->exception()); exec->clearException(); } return toRef(jsValue); }
JSStringRef JSValueCreateJSONString(JSContextRef ctx, JSValueRef apiValue, unsigned indent, JSValueRef* exception) { ExecState* exec = toJS(ctx); APIEntryShim entryShim(exec); JSValue value = toJS(exec, apiValue); String result = JSONStringify(exec, value, indent); if (exception) *exception = 0; if (exec->hadException()) { if (exception) *exception = toRef(exec, exec->exception()); exec->clearException(); return 0; } return OpaqueJSString::create(result).leakRef(); }
JSObjectRef JSValueToObject(JSContextRef ctx, JSValueRef value, JSValueRef* exception) { ExecState* exec = toJS(ctx); APIEntryShim entryShim(exec); JSValue jsValue = toJS(exec, value); JSObjectRef objectRef = toRef(jsValue.toObject(exec)); if (exec->hadException()) { if (exception) *exception = toRef(exec, exec->exception()); exec->clearException(); objectRef = 0; } return objectRef; }
JSStringRef JSValueToStringCopy(JSContextRef ctx, JSValueRef value, JSValueRef* exception) { ExecState* exec = toJS(ctx); APIEntryShim entryShim(exec); JSValue jsValue = toJS(exec, value); RefPtr<OpaqueJSString> stringRef(OpaqueJSString::create(jsValue.toString(exec))); if (exec->hadException()) { if (exception) *exception = toRef(exec, exec->exception()); exec->clearException(); stringRef.clear(); } return stringRef.release().releaseRef(); }
double JSValueToNumber(JSContextRef ctx, JSValueRef value, JSValueRef* exception) { ExecState* exec = toJS(ctx); APIEntryShim entryShim(exec); JSValue jsValue = toJS(exec, value); double number = jsValue.toNumber(exec); if (exec->hadException()) { if (exception) *exception = toRef(exec, exec->exception()); exec->clearException(); number = NaN; } return number; }
bool JSValueIsEqual(JSContextRef ctx, JSValueRef a, JSValueRef b, JSValueRef* exception) { ExecState* exec = toJS(ctx); APIEntryShim entryShim(exec); JSValue jsA = toJS(exec, a); JSValue jsB = toJS(exec, b); bool result = JSValue::equal(exec, jsA, jsB); // false if an exception is thrown if (exec->hadException()) { if (exception) *exception = toRef(exec, exec->exception()); exec->clearException(); } return result; }
bool JSObjectDeleteProperty(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception) { ExecState* exec = toJS(ctx); exec->globalData().heap->registerThread(); JSLock lock(exec); JSObject* jsObject = toJS(object); bool result = jsObject->deleteProperty(exec, propertyName->identifier(exec)); if (exec->hadException()) { if (exception) *exception = toRef(exec->exception()); exec->clearException(); } return result; }