本文整理汇总了C++中JSValue::toBoolean方法的典型用法代码示例。如果您正苦于以下问题:C++ JSValue::toBoolean方法的具体用法?C++ JSValue::toBoolean怎么用?C++ JSValue::toBoolean使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JSValue
的用法示例。
在下文中一共展示了JSValue::toBoolean方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: flagsString
static inline FlagsString flagsString(ExecState* exec, JSObject* regexp)
{
FlagsString string;
JSValue globalValue = regexp->get(exec, exec->propertyNames().global);
if (exec->hadException())
return string;
JSValue ignoreCaseValue = regexp->get(exec, exec->propertyNames().ignoreCase);
if (exec->hadException())
return string;
JSValue multilineValue = regexp->get(exec, exec->propertyNames().multiline);
if (exec->hadException())
return string;
JSValue unicodeValue = regexp->get(exec, exec->propertyNames().unicode);
unsigned index = 0;
if (globalValue.toBoolean(exec))
string[index++] = 'g';
if (ignoreCaseValue.toBoolean(exec))
string[index++] = 'i';
if (multilineValue.toBoolean(exec))
string[index++] = 'm';
if (unicodeValue.toBoolean(exec))
string[index++] = 'u';
ASSERT(index < string.size());
string[index] = 0;
return string;
}
示例2: populateContextMenuItems
static void populateContextMenuItems(ExecState* exec, JSArray* array, ContextMenu& menu)
{
for (size_t i = 0; i < array->length(); ++i) {
JSObject* item = asObject(array->getIndex(exec, i));
JSValue label = item->get(exec, Identifier::fromString(exec, "label"));
JSValue type = item->get(exec, Identifier::fromString(exec, "type"));
JSValue id = item->get(exec, Identifier::fromString(exec, "id"));
JSValue enabled = item->get(exec, Identifier::fromString(exec, "enabled"));
JSValue checked = item->get(exec, Identifier::fromString(exec, "checked"));
JSValue subItems = item->get(exec, Identifier::fromString(exec, "subItems"));
if (!type.isString())
continue;
String typeString = type.toWTFString(exec);
if (typeString == "separator") {
ContextMenuItem item(SeparatorType, ContextMenuItemTagNoAction, String());
menu.appendItem(item);
} else if (typeString == "subMenu" && subItems.inherits(JSArray::info())) {
ContextMenu subMenu;
JSArray* subItemsArray = asArray(subItems);
populateContextMenuItems(exec, subItemsArray, subMenu);
ContextMenuItem item(SubmenuType, ContextMenuItemTagNoAction, label.toWTFString(exec), &subMenu);
menu.appendItem(item);
} else {
ContextMenuAction typedId = static_cast<ContextMenuAction>(ContextMenuItemBaseCustomTag + id.toInt32(exec));
ContextMenuItem menuItem((typeString == "checkbox" ? CheckableActionType : ActionType), typedId, label.toWTFString(exec));
if (!enabled.isUndefined())
menuItem.setEnabled(enabled.toBoolean(exec));
if (!checked.isUndefined())
menuItem.setChecked(checked.toBoolean(exec));
menu.appendItem(menuItem);
}
}
}
示例3: hasBreakpoint
bool ScriptDebugServer::hasBreakpoint(intptr_t sourceID, const TextPosition& position) const
{
if (!m_breakpointsActivated)
return false;
SourceIdToBreakpointsMap::const_iterator it = m_sourceIdToBreakpoints.find(sourceID);
if (it == m_sourceIdToBreakpoints.end())
return false;
int lineNumber = position.m_line.oneBasedInt();
if (lineNumber <= 0)
return false;
LineToBreakpointMap::const_iterator breakIt = it->second.find(lineNumber);
if (breakIt == it->second.end())
return false;
// An empty condition counts as no condition which is equivalent to "true".
if (breakIt->second.condition.isEmpty())
return true;
JSValue exception;
JSValue result = m_currentCallFrame->evaluate(stringToUString(breakIt->second.condition), exception);
if (exception) {
// An erroneous condition counts as "false".
return false;
}
return result.toBoolean(m_currentCallFrame->scopeChain()->globalObject->globalExec());
}
示例4: setJSXMLHttpRequestWithCredentials
void setJSXMLHttpRequestWithCredentials(ExecState* exec, JSObject* thisObject, JSValue value)
{
XMLHttpRequest* imp = static_cast<XMLHttpRequest*>(static_cast<JSXMLHttpRequest*>(thisObject)->impl());
ExceptionCode ec = 0;
imp->setWithCredentials(value.toBoolean(exec), ec);
setDOMException(exec, ec);
}
示例5: hasBreakpoint
bool Debugger::hasBreakpoint(SourceID sourceID, const TextPosition& position, Breakpoint *hitBreakpoint)
{
if (!m_breakpointsActivated)
return false;
SourceIDToBreakpointsMap::const_iterator it = m_sourceIDToBreakpoints.find(sourceID);
if (it == m_sourceIDToBreakpoints.end())
return false;
unsigned line = position.m_line.zeroBasedInt();
unsigned column = position.m_column.zeroBasedInt();
LineToBreakpointsMap::const_iterator breaksIt = it->value.find(line);
if (breaksIt == it->value.end())
return false;
bool hit = false;
const BreakpointsInLine& breakpoints = breaksIt->value;
unsigned breakpointsCount = breakpoints.size();
unsigned i;
for (i = 0; i < breakpointsCount; i++) {
unsigned breakLine = breakpoints[i].line;
unsigned breakColumn = breakpoints[i].column;
// Since frontend truncates the indent, the first statement in a line must match the breakpoint (line,0).
ASSERT(this == m_currentCallFrame->codeBlock()->globalObject()->debugger());
if ((line != m_lastExecutedLine && line == breakLine && !breakColumn)
|| (line == breakLine && column == breakColumn)) {
hit = true;
break;
}
}
if (!hit)
return false;
if (hitBreakpoint)
*hitBreakpoint = breakpoints[i];
if (breakpoints[i].condition.isEmpty())
return true;
// We cannot stop in the debugger while executing condition code,
// so make it looks like the debugger is already paused.
TemporaryPausedState pausedState(*this);
JSValue exception;
DebuggerCallFrame* debuggerCallFrame = currentDebuggerCallFrame();
JSValue result = debuggerCallFrame->evaluate(breakpoints[i].condition, exception);
// We can lose the debugger while executing JavaScript.
if (!m_currentCallFrame)
return false;
if (exception) {
// An erroneous condition counts as "false".
handleExceptionInBreakpointCondition(m_currentCallFrame, exception);
return false;
}
return result.toBoolean(m_currentCallFrame);
}
示例6: 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);
}
示例7: JSValueToBoolean
bool JSValueToBoolean(JSContextRef ctx, JSValueRef value)
{
ExecState* exec = toJS(ctx);
APIEntryShim entryShim(exec);
JSValue jsValue = toJS(exec, value);
return jsValue.toBoolean(exec);
}
示例8: getDirectory
JSValue JSDirectoryEntry::getDirectory(ExecState* exec)
{
DirectoryEntry* imp = static_cast<DirectoryEntry*>(impl());
const String& path = valueToStringWithUndefinedOrNullCheck(exec, exec->argument(0));
if (exec->hadException())
return jsUndefined();
int argsCount = exec->argumentCount();
if (argsCount <= 1) {
imp->getDirectory(path);
return jsUndefined();
}
RefPtr<Flags> flags;
if (!exec->argument(1).isNull() && !exec->argument(1).isUndefined() && exec->argument(1).isObject() && !exec->argument(1).inherits(&JSFlags::s_info)) {
JSObject* object = exec->argument(1).getObject();
flags = Flags::create();
JSValue jsCreate = object->get(exec, Identifier(exec, "create"));
flags->setCreate(jsCreate.toBoolean(exec));
JSValue jsExclusive = object->get(exec, Identifier(exec, "exclusive"));
flags->setExclusive(jsExclusive.toBoolean(exec));
} else
flags = toFlags(exec->argument(1));
if (exec->hadException())
return jsUndefined();
RefPtr<EntryCallback> successCallback;
if (exec->argumentCount() > 2 && !exec->argument(2).isNull() && !exec->argument(2).isUndefined()) {
if (!exec->argument(2).isObject()) {
setDOMException(exec, TYPE_MISMATCH_ERR);
return jsUndefined();
}
successCallback = JSEntryCallback::create(asObject(exec->argument(2)), globalObject());
}
RefPtr<ErrorCallback> errorCallback;
if (exec->argumentCount() > 3 && !exec->argument(3).isNull() && !exec->argument(3).isUndefined()) {
if (!exec->argument(3).isObject()) {
setDOMException(exec, TYPE_MISMATCH_ERR);
return jsUndefined();
}
errorCallback = JSErrorCallback::create(asObject(exec->argument(3)), globalObject());
}
imp->getDirectory(path, flags, successCallback, errorCallback);
return jsUndefined();
}
示例9: JSValueToBoolean
bool JSValueToBoolean(JSContextRef ctx, JSValueRef value)
{
ExecState* exec = toJS(ctx);
exec->globalData().heap.registerThread();
JSLock lock(exec);
JSValue jsValue = toJS(exec, value);
return jsValue.toBoolean(exec);
}
示例10: 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();
JSC::JSLock lock(false);
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);
MarkedArgumentBuffer args;
args.append(toJS(exec, transaction));
args.append(toJS(exec, error));
JSValue result;
globalObject->globalData()->timeoutChecker.start();
if (handleEventCallType != CallTypeNone)
result = call(exec, handleEventFunction, handleEventCallType, handleEventCallData, m_callback, args);
else
result = call(exec, m_callback, callbackCallType, callbackCallData, m_callback, args);
globalObject->globalData()->timeoutChecker.stop();
if (exec->hadException()) {
reportCurrentException(exec);
// 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::updateStyleForAllDocuments();
return result.toBoolean(exec);
}
示例11: JSTryConvertToBool
JSLR_API bool _cdecl JSTryConvertToBool(JSContextRef ctx, JSValueRef value, bool* result)
{
ExecState* exec = toJS(ctx);
JSValue jsValue = toJS(exec, value);
if (jsValue.isBoolean())
{
*result = jsValue.toBoolean(exec);
return true;
}
return false;
}
示例12: JSValueToBoolean
bool JSValueToBoolean(JSContextRef ctx, JSValueRef value)
{
if (!ctx) {
ASSERT_NOT_REACHED();
return false;
}
ExecState* exec = toJS(ctx);
JSLockHolder locker(exec);
JSValue jsValue = toJS(exec, value);
return jsValue.toBoolean(exec);
}
示例13: showContextMenu
JSValue JSInspectorFrontendHost::showContextMenu(ExecState* exec)
{
if (exec->argumentCount() < 2)
return jsUndefined();
#if ENABLE(CONTEXT_MENUS)
Event* event = toEvent(exec->argument(0));
JSArray* array = asArray(exec->argument(1));
Vector<ContextMenuItem*> items;
for (size_t i = 0; i < array->length(); ++i) {
JSObject* item = asObject(array->getIndex(i));
JSValue label = item->get(exec, Identifier(exec, "label"));
JSValue type = item->get(exec, Identifier(exec, "type"));
JSValue id = item->get(exec, Identifier(exec, "id"));
JSValue enabled = item->get(exec, Identifier(exec, "enabled"));
JSValue checked = item->get(exec, Identifier(exec, "checked"));
if (!type.isString())
continue;
String typeString = ustringToString(type.toString(exec)->value(exec));
if (typeString == "separator") {
items.append(new ContextMenuItem(SeparatorType,
ContextMenuItemCustomTagNoAction,
String()));
} else {
ContextMenuAction typedId = static_cast<ContextMenuAction>(ContextMenuItemBaseCustomTag + id.toInt32(exec));
ContextMenuItem* menuItem = new ContextMenuItem((typeString == "checkbox" ? CheckableActionType : ActionType), typedId, ustringToString(label.toString(exec)->value(exec)));
if (!enabled.isUndefined())
menuItem->setEnabled(enabled.toBoolean(exec));
if (!checked.isUndefined())
menuItem->setChecked(checked.toBoolean(exec));
items.append(menuItem);
}
}
impl()->showContextMenu(event, items);
#endif
return jsUndefined();
}
示例14: hasBreakpoint
bool ScriptDebugServer::hasBreakpoint(intptr_t sourceID, const TextPosition& position, ScriptBreakpoint *hitBreakpoint) const
{
if (!m_breakpointsActivated)
return false;
SourceIdToBreakpointsMap::const_iterator it = m_sourceIdToBreakpoints.find(sourceID);
if (it == m_sourceIdToBreakpoints.end())
return false;
int line = position.m_line.zeroBasedInt();
int column = position.m_column.zeroBasedInt();
if (line < 0 || column < 0)
return false;
LineToBreakpointsMap::const_iterator breaksIt = it->value.find(line);
if (breaksIt == it->value.end())
return false;
bool hit = false;
const BreakpointsInLine& breaksVector = breaksIt->value;
unsigned breaksCount = breaksVector.size();
unsigned i;
for (i = 0; i < breaksCount; i++) {
int breakLine = breaksVector.at(i).lineNumber;
int breakColumn = breaksVector.at(i).columnNumber;
// Since frontend truncates the indent, the first statement in a line must match the breakpoint (line,0).
if ((line != m_lastExecutedLine && line == breakLine && !breakColumn)
|| (line == breakLine && column == breakColumn)) {
hit = true;
break;
}
}
if (!hit)
return false;
if (hitBreakpoint)
*hitBreakpoint = breaksVector.at(i);
// An empty condition counts as no condition which is equivalent to "true".
if (breaksVector.at(i).condition.isEmpty())
return true;
JSValue exception;
JSValue result = DebuggerCallFrame::evaluateWithCallFrame(m_currentCallFrame, breaksVector.at(i).condition, exception);
if (exception) {
// An erroneous condition counts as "false".
reportException(m_currentCallFrame, exception);
return false;
}
return result.toBoolean(m_currentCallFrame);
}
示例15: setJSHTMLObjectElementDeclare
void setJSHTMLObjectElementDeclare(ExecState* exec, EncodedJSValue thisValue, EncodedJSValue encodedValue)
{
JSValue value = JSValue::decode(encodedValue);
UNUSED_PARAM(exec);
JSHTMLObjectElement* castedThis = jsDynamicCast<JSHTMLObjectElement*>(JSValue::decode(thisValue));
if (!castedThis) {
throwVMTypeError(exec);
return;
}
HTMLObjectElement& impl = castedThis->impl();
bool nativeValue(value.toBoolean(exec));
if (exec->hadException())
return;
impl.setBooleanAttribute(WebCore::HTMLNames::declareAttr, nativeValue);
}