本文整理汇总了C++中JSValue::toObject方法的典型用法代码示例。如果您正苦于以下问题:C++ JSValue::toObject方法的具体用法?C++ JSValue::toObject怎么用?C++ JSValue::toObject使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JSValue
的用法示例。
在下文中一共展示了JSValue::toObject方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: new
// ECMA 15.2.2
static ALWAYS_INLINE JSObject* constructObject(ExecState* exec, const ArgList& args)
{
JSValue arg = args.at(0);
if (arg.isUndefinedOrNull())
return new (exec) JSObject(exec->lexicalGlobalObject()->emptyObjectStructure());
return arg.toObject(exec);
}
示例2: dictionary
static PassRefPtr<PositionOptions> createPositionOptions(ExecState* exec, JSValue value)
{
// Create default options.
RefPtr<PositionOptions> options = PositionOptions::create();
// Argument is optional (hence undefined is allowed), and null is allowed.
if (value.isUndefinedOrNull()) {
// Use default options.
return options.release();
}
// Given the above test, this will always yield an object.
JSObject* object = value.toObject(exec);
// Create the dictionary wrapper from the initializer object.
JSDictionary dictionary(exec, object);
if (!dictionary.tryGetProperty("enableHighAccuracy", options.get(), setEnableHighAccuracy))
return 0;
if (!dictionary.tryGetProperty("timeout", options.get(), setTimeout))
return 0;
if (!dictionary.tryGetProperty("maximumAge", options.get(), setMaximumAge))
return 0;
return options.release();
}
示例3: getTypeFlags
static std::error_code getTypeFlags(ExecState& exec, const JSValue& typeValue, ResourceFlags& flags, uint16_t (*stringToType)(const String&))
{
VM& vm = exec.vm();
auto scope = DECLARE_THROW_SCOPE(vm);
if (!typeValue.isObject())
return { };
const JSObject* object = typeValue.toObject(&exec);
ASSERT(!scope.exception());
if (!isJSArray(object))
return ContentExtensionError::JSONInvalidTriggerFlagsArray;
const JSArray* array = jsCast<const JSArray*>(object);
unsigned length = array->length();
for (unsigned i = 0; i < length; ++i) {
const JSValue value = array->getIndex(&exec, i);
if (scope.exception() || !value)
return ContentExtensionError::JSONInvalidObjectInTriggerFlagsArray;
String name = value.toWTFString(&exec);
uint16_t type = stringToType(name);
if (!type)
return ContentExtensionError::JSONInvalidStringInTriggerFlagsArray;
flags |= type;
}
return { };
}
示例4: objectProtoFuncToString
EncodedJSValue JSC_HOST_CALL objectProtoFuncToString(ExecState* exec)
{
VM& vm = exec->vm();
JSValue thisValue = exec->thisValue().toThis(exec, StrictMode);
if (thisValue.isUndefinedOrNull())
return JSValue::encode(thisValue.isUndefined() ? vm.smallStrings.undefinedObjectString() : vm.smallStrings.nullObjectString());
JSObject* thisObject = thisValue.toObject(exec);
JSValue stringTag = thisObject->get(exec, exec->propertyNames().toStringTagSymbol);
if (stringTag.isString()) {
JSRopeString::RopeBuilder<RecordOverflow> ropeBuilder(vm);
ropeBuilder.append(vm.smallStrings.objectStringStart());
ropeBuilder.append(jsCast<JSString*>(stringTag));
ropeBuilder.append(vm.smallStrings.singleCharacterString(']'));
if(ropeBuilder.hasOverflowed())
return JSValue::encode(throwOutOfMemoryError(exec));
return JSValue::encode(ropeBuilder.release());
}
JSString* result = thisObject->structure(vm)->objectToStringValue();
if (!result) {
RefPtr<StringImpl> newString = WTF::tryMakeString("[object ", thisObject->methodTable(exec->vm())->className(thisObject), "]");
if (!newString)
return JSValue::encode(throwOutOfMemoryError(exec));
result = jsNontrivialString(&vm, newString.release());
thisObject->structure(vm)->setObjectToStringValue(vm, result);
}
return JSValue::encode(result);
}
示例5: throwVMError
template<> EncodedJSValue JSC_HOST_CALL JSTestEventConstructorConstructor::construct(ExecState* state)
{
auto* jsConstructor = jsCast<JSTestEventConstructorConstructor*>(state->callee());
if (!jsConstructor->scriptExecutionContext())
return throwVMError(state, createReferenceError(state, "Constructor associated execution context is unavailable"));
if (UNLIKELY(state->argumentCount() < 1))
return throwVMError(state, createNotEnoughArgumentsError(state));
AtomicString eventType = state->argument(0).toString(state)->toAtomicString(state);
if (UNLIKELY(state->hadException()))
return JSValue::encode(jsUndefined());
TestEventConstructorInit eventInit;
JSValue initializerValue = state->argument(1);
if (!initializerValue.isUndefinedOrNull()) {
// Given the above test, this will always yield an object.
JSObject* initializerObject = initializerValue.toObject(state);
ASSERT(!state->hadException());
// Create the dictionary wrapper from the initializer object.
JSDictionary dictionary(state, initializerObject);
// Attempt to fill in the EventInit.
if (!fillTestEventConstructorInit(eventInit, dictionary))
return JSValue::encode(jsUndefined());
}
Ref<TestEventConstructor> event = TestEventConstructor::createForBindings(eventType, eventInit);
return JSValue::encode(toJS(state, jsConstructor->globalObject(), event));
}
示例6: new
// ECMA 15.2.2
static ALWAYS_INLINE JSObject* constructObject(ExecState* exec, const ArgList& args)
{
JSValue* arg = args.at(exec, 0);
if (arg->isUndefinedOrNull())
return new (exec) JSObject(exec->lexicalGlobalObject()->objectPrototype());
return arg->toObject(exec);
}
示例7: constructJSKeyboardEvent
EncodedJSValue JSC_HOST_CALL JSKeyboardEventConstructor::constructJSKeyboardEvent(ExecState* exec)
{
JSKeyboardEventConstructor* jsConstructor = jsCast<JSKeyboardEventConstructor*>(exec->callee());
ScriptExecutionContext* executionContext = jsConstructor->scriptExecutionContext();
if (!executionContext)
return throwVMError(exec, createReferenceError(exec, "Constructor associated execution context is unavailable"));
AtomicString eventType = exec->argument(0).toString(exec)->value(exec);
if (exec->hadException())
return JSValue::encode(jsUndefined());
KeyboardEventInit eventInit;
JSValue initializerValue = exec->argument(1);
if (!initializerValue.isUndefinedOrNull()) {
// Given the above test, this will always yield an object.
JSObject* initializerObject = initializerValue.toObject(exec);
// Create the dictionary wrapper from the initializer object.
JSDictionary dictionary(exec, initializerObject);
// Attempt to fill in the EventInit.
if (!fillKeyboardEventInit(eventInit, dictionary))
return JSValue::encode(jsUndefined());
}
RefPtr<KeyboardEvent> event = KeyboardEvent::create(eventType, eventInit);
return JSValue::encode(toJS(exec, jsConstructor->globalObject(), event.get()));
}
示例8: objectProtoFuncHasOwnProperty
EncodedJSValue JSC_HOST_CALL objectProtoFuncHasOwnProperty(ExecState* exec)
{
JSValue thisValue = exec->thisValue().toThis(exec, StrictMode);
auto propertyName = exec->argument(0).toPropertyKey(exec);
if (exec->hadException())
return JSValue::encode(jsUndefined());
return JSValue::encode(jsBoolean(thisValue.toObject(exec)->hasOwnProperty(exec, propertyName)));
}
示例9: valueToDate
double valueToDate(ExecState* exec, JSValue value)
{
if (value.isNumber())
return value.asNumber();
if (!value.inherits(DateInstance::info()))
return std::numeric_limits<double>::quiet_NaN();
return static_cast<DateInstance*>(value.toObject(exec))->internalNumber();
}
示例10: loadEncodedRules
static std::error_code loadEncodedRules(ExecState& exec, const String& rules, Vector<ContentExtensionRule>& ruleList)
{
VM& vm = exec.vm();
auto scope = DECLARE_THROW_SCOPE(vm);
// FIXME: JSONParse should require callbacks instead of an ExecState.
const JSValue decodedRules = JSONParse(&exec, rules);
if (scope.exception() || !decodedRules)
return ContentExtensionError::JSONInvalid;
if (!decodedRules.isObject())
return ContentExtensionError::JSONTopLevelStructureNotAnObject;
const JSObject* topLevelObject = decodedRules.toObject(&exec);
if (!topLevelObject || scope.exception())
return ContentExtensionError::JSONTopLevelStructureNotAnObject;
if (!isJSArray(topLevelObject))
return ContentExtensionError::JSONTopLevelStructureNotAnArray;
const JSArray* topLevelArray = jsCast<const JSArray*>(topLevelObject);
Vector<ContentExtensionRule> localRuleList;
unsigned length = topLevelArray->length();
const unsigned maxRuleCount = 50000;
if (length > maxRuleCount)
return ContentExtensionError::JSONTooManyRules;
for (unsigned i = 0; i < length; ++i) {
const JSValue value = topLevelArray->getIndex(&exec, i);
if (scope.exception() || !value)
return ContentExtensionError::JSONInvalidObjectInTopLevelArray;
const JSObject* ruleObject = value.toObject(&exec);
if (!ruleObject || scope.exception())
return ContentExtensionError::JSONInvalidRule;
auto error = loadRule(exec, *ruleObject, localRuleList);
if (error)
return error;
}
ruleList = WTFMove(localRuleList);
return { };
}
示例11: args
static ALWAYS_INLINE JSObject* constructObject(ExecState* exec)
{
JSGlobalObject* globalObject = exec->callee()->globalObject();
ArgList args(exec);
JSValue arg = args.at(0);
if (arg.isUndefinedOrNull())
return constructEmptyObject(exec, globalObject->objectPrototype());
return arg.toObject(exec, globalObject);
}
示例12: construct
JSObject* BalRuntimeObjectImp::construct(ExecState* exec, const ArgList& args)
{
// ECMA 15.2.2.1 (?)
CallData callData;
CallType callType = getCallData(callData);
JSValue* val = call(exec, this, callType, callData, this, args);
if (!val || val->type() == NullType || val->type() == UndefinedType)
return new (exec) JSObject(exec->lexicalGlobalObject()->objectPrototype()->prototype());
else
return val->toObject(exec);
}
示例13: reportException
void reportException(ExecState* exec, JSValue exception, CachedScript* cachedScript)
{
if (isTerminatedExecutionException(exception))
return;
Interpreter::ErrorHandlingMode mode(exec);
RefPtr<ScriptCallStack> callStack(createScriptCallStackFromException(exec, exception, ScriptCallStack::maxCallStackSizeToCapture));
exec->clearException();
exec->clearSupplementaryExceptionInfo();
JSDOMGlobalObject* globalObject = jsCast<JSDOMGlobalObject*>(exec->lexicalGlobalObject());
if (JSDOMWindow* window = jsDynamicCast<JSDOMWindow*>(globalObject)) {
if (!window->impl()->isCurrentlyDisplayedInFrame())
return;
}
int lineNumber = 0;
int columnNumber = 0;
String exceptionSourceURL;
if (callStack->size()) {
const ScriptCallFrame& frame = callStack->at(0);
lineNumber = frame.lineNumber();
columnNumber = frame.columnNumber();
exceptionSourceURL = frame.sourceURL();
} else {
// There may not be an exceptionStack for a <script> SyntaxError. Fallback to getting at least the line and sourceURL from the exception.
JSObject* exceptionObject = exception.toObject(exec);
JSValue lineValue = exceptionObject->getDirect(exec->vm(), Identifier(exec, "line"));
lineNumber = lineValue && lineValue.isNumber() ? int(lineValue.toNumber(exec)) : 0;
JSValue columnValue = exceptionObject->getDirect(exec->vm(), Identifier(exec, "column"));
columnNumber = columnValue && columnValue.isNumber() ? int(columnValue.toNumber(exec)) : 0;
JSValue sourceURLValue = exceptionObject->getDirect(exec->vm(), Identifier(exec, "sourceURL"));
exceptionSourceURL = sourceURLValue && sourceURLValue.isString() ? sourceURLValue.toString(exec)->value(exec) : ASCIILiteral("undefined");
}
String errorMessage;
if (ExceptionBase* exceptionBase = toExceptionBase(exception))
errorMessage = exceptionBase->message() + ": " + exceptionBase->description();
else {
// FIXME: <http://webkit.org/b/115087> Web Inspector: WebCore::reportException should not evaluate JavaScript handling exceptions
// If this is a custon exception object, call toString on it to try and get a nice string representation for the exception.
errorMessage = exception.toString(exec)->value(exec);
exec->clearException();
exec->clearSupplementaryExceptionInfo();
}
ScriptExecutionContext* scriptExecutionContext = globalObject->scriptExecutionContext();
scriptExecutionContext->reportException(errorMessage, lineNumber, columnNumber, exceptionSourceURL, callStack->size() ? callStack : 0, cachedScript);
}
示例14: JSValueToObject
EXPORT
JSObjectRef JSValueToObject(JSContextRef ctx, JSValueRef value, JSValueRef* exception)
{
JSLock lock;
ExecState* exec = toJS(ctx);
JSValue* jsValue = toJS(value);
JSObjectRef objectRef = toRef(jsValue->toObject(exec));
if (exec->hadException()) {
if (exception)
*exception = toRef(exec->exception());
exec->clearException();
objectRef = 0;
}
return objectRef;
}
示例15: JSValueToObject
JSObjectRef JSValueToObject(JSContextRef ctx, JSValueRef value, JSValueRef* exception)
{
if (!ctx) {
ASSERT_NOT_REACHED();
return 0;
}
ExecState* exec = toJS(ctx);
JSLockHolder locker(exec);
JSValue jsValue = toJS(exec, value);
JSObjectRef objectRef = toRef(jsValue.toObject(exec));
if (handleExceptionIfNeeded(exec, exception) == ExceptionStatus::DidThrow)
objectRef = 0;
return objectRef;
}