本文整理汇总了C++中JSValue::inherits方法的典型用法代码示例。如果您正苦于以下问题:C++ JSValue::inherits方法的具体用法?C++ JSValue::inherits怎么用?C++ JSValue::inherits使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JSValue
的用法示例。
在下文中一共展示了JSValue::inherits方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: type
JSValue JSInjectedScriptHost::type(ExecState* exec)
{
if (exec->argumentCount() < 1)
return jsUndefined();
JSValue value = exec->argument(0);
if (value.isString())
return jsString(exec, String("string"));
if (value.inherits(&JSArray::s_info))
return jsString(exec, String("array"));
if (value.isBoolean())
return jsString(exec, String("boolean"));
if (value.isNumber())
return jsString(exec, String("number"));
if (value.inherits(&DateInstance::s_info))
return jsString(exec, String("date"));
if (value.inherits(&RegExpObject::s_info))
return jsString(exec, String("regexp"));
if (value.inherits(&JSNode::s_info))
return jsString(exec, String("node"));
if (value.inherits(&JSNodeList::s_info))
return jsString(exec, String("array"));
if (value.inherits(&JSHTMLCollection::s_info))
return jsString(exec, String("array"));
if (value.inherits(&JSInt8Array::s_info) || value.inherits(&JSInt16Array::s_info) || value.inherits(&JSInt32Array::s_info))
return jsString(exec, String("array"));
if (value.inherits(&JSUint8Array::s_info) || value.inherits(&JSUint16Array::s_info) || value.inherits(&JSUint32Array::s_info))
return jsString(exec, String("array"));
if (value.inherits(&JSFloat32Array::s_info) || value.inherits(&JSFloat64Array::s_info))
return jsString(exec, String("array"));
return jsUndefined();
}
示例2: isInterruptedExecutionException
bool isInterruptedExecutionException(JSValue value)
{
return value.inherits(&InterruptedExecutionError::s_info);
}
示例3: isTerminatedExecutionException
bool isTerminatedExecutionException(JSValue value)
{
return value.inherits(TerminatedExecutionError::info());
}
示例4: subtype
JSValue JSInjectedScriptHost::subtype(ExecState* exec)
{
if (exec->argumentCount() < 1)
return jsUndefined();
JSValue value = exec->uncheckedArgument(0);
if (value.isString())
return exec->vm().smallStrings.stringString();
if (value.isBoolean())
return exec->vm().smallStrings.booleanString();
if (value.isNumber())
return exec->vm().smallStrings.numberString();
if (value.isSymbol())
return exec->vm().smallStrings.symbolString();
JSObject* object = asObject(value);
if (object) {
if (object->isErrorInstance())
return jsNontrivialString(exec, ASCIILiteral("error"));
// Consider class constructor functions class objects.
JSFunction* function = jsDynamicCast<JSFunction*>(value);
if (function && function->isClassConstructorFunction())
return jsNontrivialString(exec, ASCIILiteral("class"));
}
if (value.inherits(JSArray::info()))
return jsNontrivialString(exec, ASCIILiteral("array"));
if (value.inherits(DirectArguments::info()) || value.inherits(ScopedArguments::info()))
return jsNontrivialString(exec, ASCIILiteral("array"));
if (value.inherits(DateInstance::info()))
return jsNontrivialString(exec, ASCIILiteral("date"));
if (value.inherits(RegExpObject::info()))
return jsNontrivialString(exec, ASCIILiteral("regexp"));
if (value.inherits(JSMap::info()))
return jsNontrivialString(exec, ASCIILiteral("map"));
if (value.inherits(JSSet::info()))
return jsNontrivialString(exec, ASCIILiteral("set"));
if (value.inherits(JSWeakMap::info()))
return jsNontrivialString(exec, ASCIILiteral("weakmap"));
if (value.inherits(JSWeakSet::info()))
return jsNontrivialString(exec, ASCIILiteral("weakset"));
if (value.inherits(JSArrayIterator::info())
|| value.inherits(JSMapIterator::info())
|| value.inherits(JSSetIterator::info())
|| value.inherits(JSStringIterator::info())
|| value.inherits(JSPropertyNameIterator::info()))
return jsNontrivialString(exec, ASCIILiteral("iterator"));
if (object && object->getDirect(exec->vm(), exec->vm().propertyNames->builtinNames().arrayIteratorNextIndexPrivateName()))
return jsNontrivialString(exec, ASCIILiteral("iterator"));
if (value.inherits(JSInt8Array::info()) || value.inherits(JSInt16Array::info()) || value.inherits(JSInt32Array::info()))
return jsNontrivialString(exec, ASCIILiteral("array"));
if (value.inherits(JSUint8Array::info()) || value.inherits(JSUint16Array::info()) || value.inherits(JSUint32Array::info()))
return jsNontrivialString(exec, ASCIILiteral("array"));
if (value.inherits(JSFloat32Array::info()) || value.inherits(JSFloat64Array::info()))
return jsNontrivialString(exec, ASCIILiteral("array"));
return impl().subtype(exec, value);
}
示例5: constructJSBlob
EncodedJSValue JSC_HOST_CALL JSBlobConstructor::constructJSBlob(ExecState* exec)
{
JSBlobConstructor* jsConstructor = jsCast<JSBlobConstructor*>(exec->callee());
ScriptExecutionContext* context = jsConstructor->scriptExecutionContext();
if (!context)
return throwVMError(exec, createReferenceError(exec, "Blob constructor associated document is unavailable"));
if (!exec->argumentCount()) {
RefPtr<Blob> blob = Blob::create();
return JSValue::encode(CREATE_DOM_WRAPPER(exec, jsConstructor->globalObject(), Blob, blob.get()));
}
JSValue firstArg = exec->argument(0);
if (!isJSArray(firstArg))
return throwVMError(exec, createTypeError(exec, "First argument of the constructor is not of type Array"));
String type;
String endings = "transparent";
if (exec->argumentCount() > 1) {
JSValue blobPropertyBagValue = exec->argument(1);
if (!blobPropertyBagValue.isObject())
return throwVMError(exec, createTypeError(exec, "Second argument of the constructor is not of type Object"));
// Given the above test, this will always yield an object.
JSObject* blobPropertyBagObject = blobPropertyBagValue.toObject(exec);
// Create the dictionary wrapper from the initializer object.
JSDictionary dictionary(exec, blobPropertyBagObject);
// Attempt to get the endings property and validate it.
bool containsEndings = dictionary.get("endings", endings);
if (exec->hadException())
return JSValue::encode(jsUndefined());
if (containsEndings) {
if (endings != "transparent" && endings != "native")
return throwVMError(exec, createTypeError(exec, "The endings property must be either \"transparent\" or \"native\""));
}
// Attempt to get the type property.
dictionary.get("type", type);
if (exec->hadException())
return JSValue::encode(jsUndefined());
if (!type.containsOnlyASCII())
return throwVMError(exec, createSyntaxError(exec, "type must consist of ASCII characters"));
}
ASSERT(endings == "transparent" || endings == "native");
// FIXME: this would be better if the WebKitBlobBuilder were a stack object to avoid the allocation.
RefPtr<WebKitBlobBuilder> blobBuilder = WebKitBlobBuilder::create();
JSArray* array = asArray(firstArg);
unsigned length = array->length();
for (unsigned i = 0; i < length; ++i) {
JSValue item = array->getIndex(i);
#if ENABLE(BLOB)
if (item.inherits(&JSArrayBuffer::s_info))
blobBuilder->append(context, toArrayBuffer(item));
else if (item.inherits(&JSArrayBufferView::s_info))
blobBuilder->append(toArrayBufferView(item));
else
#endif
if (item.inherits(&JSBlob::s_info))
blobBuilder->append(toBlob(item));
else {
String string = ustringToString(item.toString(exec)->value(exec));
if (exec->hadException())
return JSValue::encode(jsUndefined());
blobBuilder->append(string, endings, ASSERT_NO_EXCEPTION);
}
}
RefPtr<Blob> blob = blobBuilder->getBlob(type);
return JSValue::encode(CREATE_DOM_WRAPPER(exec, jsConstructor->globalObject(), Blob, blob.get()));
}
示例6: KJSValueToCFTypeInternal
//--------------------------------------------------------------------------
// KJSValueToCFTypeInternal
//--------------------------------------------------------------------------
// Caller is responsible for releasing the returned CFTypeRef
CFTypeRef KJSValueToCFTypeInternal(JSValue inValue, ExecState *exec, ObjectImpList* inImps)
{
if (!inValue)
return 0;
CFTypeRef result = 0;
JSGlueAPIEntry entry;
if (inValue.isBoolean())
{
result = inValue.toBoolean(exec) ? kCFBooleanTrue : kCFBooleanFalse;
RetainCFType(result);
return result;
}
if (inValue.isString())
{
UString uString = inValue.toString(exec);
result = UStringToCFString(uString);
return result;
}
if (inValue.isNumber())
{
double number1 = inValue.toNumber(exec);
double number2 = (double)inValue.toInteger(exec);
if (number1 == number2)
{
int intValue = (int)number2;
result = CFNumberCreate(0, kCFNumberIntType, &intValue);
}
else
{
result = CFNumberCreate(0, kCFNumberDoubleType, &number1);
}
return result;
}
if (inValue.isObject())
{
if (inValue.inherits(&UserObjectImp::s_info)) {
UserObjectImp* userObjectImp = static_cast<UserObjectImp *>(asObject(inValue));
JSUserObject* ptr = userObjectImp->GetJSUserObject();
if (ptr)
{
result = ptr->CopyCFValue();
}
}
else
{
JSObject *object = inValue.toObject(exec);
UInt8 isArray = false;
// if two objects reference each
JSObject* imp = object;
ObjectImpList* temp = inImps;
while (temp) {
if (imp == temp->imp) {
return CFRetain(GetCFNull());
}
temp = temp->next;
}
ObjectImpList imps;
imps.next = inImps;
imps.imp = imp;
//[...] HACK since we do not have access to the class info we use class name instead
#if 0
if (object->inherits(&ArrayInstanceImp::s_info))
#else
if (object->className() == "Array")
#endif
{
isArray = true;
JSGlueGlobalObject* globalObject = static_cast<JSGlueGlobalObject*>(exec->dynamicGlobalObject());
if (globalObject && (globalObject->Flags() & kJSFlagConvertAssociativeArray)) {
PropertyNameArray propNames(exec);
object->getPropertyNames(exec, propNames);
PropertyNameArray::const_iterator iter = propNames.begin();
PropertyNameArray::const_iterator end = propNames.end();
while(iter != end && isArray)
{
Identifier propName = *iter;
UString ustr = propName.ustring();
const UniChar* uniChars = (const UniChar*)ustr.characters();
int size = ustr.length();
while (size--) {
if (uniChars[size] < '0' || uniChars[size] > '9') {
isArray = false;
break;
}
}
iter++;
//.........这里部分代码省略.........
示例7: regExpProtoFuncExec
JSValue JSC_HOST_CALL regExpProtoFuncExec(ExecState* exec, JSObject*, JSValue thisValue, const ArgList& args)
{
if (!thisValue.inherits(&RegExpObject::info))
return throwError(exec, TypeError);
return asRegExpObject(thisValue)->exec(exec, args);
}
示例8: arrayProtoFuncToString
EncodedJSValue JSC_HOST_CALL arrayProtoFuncToString(ExecState* exec)
{
JSValue thisValue = exec->hostThisValue();
bool isRealArray = isJSArray(&exec->globalData(), thisValue);
if (!isRealArray && !thisValue.inherits(&JSArray::info))
return throwVMTypeError(exec);
JSArray* thisObj = asArray(thisValue);
HashSet<JSObject*>& arrayVisitedElements = exec->globalData().arrayVisitedElements;
if (arrayVisitedElements.size() >= MaxSmallThreadReentryDepth) {
if (arrayVisitedElements.size() >= exec->globalData().maxReentryDepth)
return throwVMError(exec, createStackOverflowError(exec));
}
bool alreadyVisited = !arrayVisitedElements.add(thisObj).second;
if (alreadyVisited)
return JSValue::encode(jsEmptyString(exec)); // return an empty string, avoiding infinite recursion.
//FYWEBKITMOD begin: setting up StringJoiner (while integrating r148721 due to fix of bug 114779). But not using 'ConstructFromLiteral' optimization which we dont have in our webkit.
unsigned length = thisObj->get(exec, exec->propertyNames().length).toUInt32(exec);
if (exec->hadException())
return JSValue::encode(jsUndefined());
//WebCore::String separator(",", WebCore::String::ConstructFromLiteral);
//JSStringJoiner stringJoiner(separator, length);
JSStringJoiner stringJoiner(",", length);
//FYWEBKITMOD end
unsigned totalSize = length ? length - 1 : 0;
Vector<RefPtr<UString::Rep>, 256> strBuffer(length);
for (unsigned k = 0; k < length; k++) {
JSValue element;
if (isRealArray && thisObj->canGetIndex(k))
element = thisObj->getIndex(k);
else {
element = thisObj->get(exec, k);
//FYWEBKITMOD begin: added while integrating r148721 due to fix of bug 114779
if (exec->hadException())
return JSValue::encode(jsUndefined());
//FYWEBKITMOD end
}
//FYWEBKITMOD begin: removed (USE_FIX 1) old implementation which joined the strings manually and added usage of JSStringJoiner (while integrating r148721 due to fix of bug 114779)
#define USE_FIX 1 //keep this defined!!!
#ifdef USE_FIX
if (element.isUndefinedOrNull())
stringJoiner.append(WebCore::String()); //FYWEBKITMOD:
else
stringJoiner.append(element.toString(exec).rep()); //FYWEBKITMOD: using toString() instead of new toWTFString(). Only difference is an optimization used in the toWTFString() case.
if (exec->hadException())
return JSValue::encode(jsUndefined());
}
arrayVisitedElements.remove(thisObj);
return JSValue::encode(stringJoiner.build(exec));
#else
if (element.isUndefinedOrNull())
continue;
UString str = element.toString(exec);
strBuffer[k] = str.rep();
totalSize += str.size();
if (!strBuffer.data()) {
throwOutOfMemoryError(exec);
}
if (exec->hadException())
break;
}