JSValue JSInjectedScriptHost::getInternalProperties(ExecState* exec) { if (exec->argumentCount() < 1) return jsUndefined(); JSValue value = exec->uncheckedArgument(0); #if ENABLE(PROMISES) if (JSPromise* promise = jsDynamicCast<JSPromise*>(value)) { unsigned index = 0; JSArray* array = constructEmptyArray(exec, nullptr); switch (promise->status(exec->vm())) { case JSPromise::Status::Pending: array->putDirectIndex(exec, index++, constructInternalProperty(exec, ASCIILiteral("status"), jsNontrivialString(exec, ASCIILiteral("pending")))); break; case JSPromise::Status::Fulfilled: array->putDirectIndex(exec, index++, constructInternalProperty(exec, ASCIILiteral("status"), jsNontrivialString(exec, ASCIILiteral("resolved")))); array->putDirectIndex(exec, index++, constructInternalProperty(exec, ASCIILiteral("result"), promise->result(exec->vm()))); break; case JSPromise::Status::Rejected: array->putDirectIndex(exec, index++, constructInternalProperty(exec, ASCIILiteral("status"), jsNontrivialString(exec, ASCIILiteral("rejected")))); array->putDirectIndex(exec, index++, constructInternalProperty(exec, ASCIILiteral("result"), promise->result(exec->vm()))); break; } // FIXME: <https://webkit.org/b/141664> Web Inspector: ES6: Improved Support for Promises - Promise Reactions return array; } #endif if (JSBoundFunction* boundFunction = jsDynamicCast<JSBoundFunction*>(value)) { unsigned index = 0; JSArray* array = constructEmptyArray(exec, nullptr, 3); array->putDirectIndex(exec, index++, constructInternalProperty(exec, "targetFunction", boundFunction->targetFunction())); array->putDirectIndex(exec, index++, constructInternalProperty(exec, "boundThis", boundFunction->boundThis())); array->putDirectIndex(exec, index++, constructInternalProperty(exec, "boundArgs", boundFunction->boundArgs())); return array; } if (JSArrayIterator* arrayIterator = jsDynamicCast<JSArrayIterator*>(value)) { String kind; switch (arrayIterator->kind(exec)) { case ArrayIterateKey: kind = ASCIILiteral("key"); break; case ArrayIterateValue: kind = ASCIILiteral("value"); break; case ArrayIterateKeyValue: kind = ASCIILiteral("key+value"); break; } unsigned index = 0; JSArray* array = constructEmptyArray(exec, nullptr, 2); array->putDirectIndex(exec, index++, constructInternalProperty(exec, "array", arrayIterator->iteratedValue(exec))); array->putDirectIndex(exec, index++, constructInternalProperty(exec, "kind", jsNontrivialString(exec, kind))); return array; } if (JSMapIterator* mapIterator = jsDynamicCast<JSMapIterator*>(value)) { String kind; switch (mapIterator->kind()) { case MapIterateKey: kind = ASCIILiteral("key"); break; case MapIterateValue: kind = ASCIILiteral("value"); break; case MapIterateKeyValue: kind = ASCIILiteral("key+value"); break; } unsigned index = 0; JSArray* array = constructEmptyArray(exec, nullptr, 2); array->putDirectIndex(exec, index++, constructInternalProperty(exec, "map", mapIterator->iteratedValue())); array->putDirectIndex(exec, index++, constructInternalProperty(exec, "kind", jsNontrivialString(exec, kind))); return array; } if (JSSetIterator* setIterator = jsDynamicCast<JSSetIterator*>(value)) { String kind; switch (setIterator->kind()) { case SetIterateKey: kind = ASCIILiteral("key"); break; case SetIterateValue: kind = ASCIILiteral("value"); break; case SetIterateKeyValue: kind = ASCIILiteral("key+value"); break; } unsigned index = 0; JSArray* array = constructEmptyArray(exec, nullptr, 2); array->putDirectIndex(exec, index++, constructInternalProperty(exec, "set", setIterator->iteratedValue())); array->putDirectIndex(exec, index++, constructInternalProperty(exec, "kind", jsNontrivialString(exec, kind))); return array; } if (JSStringIterator* stringIterator = jsDynamicCast<JSStringIterator*>(value)) { unsigned index = 0; JSArray* array = constructEmptyArray(exec, nullptr, 1); array->putDirectIndex(exec, index++, constructInternalProperty(exec, "string", stringIterator->iteratedValue(exec))); return array; } return jsUndefined(); }
JSValue JSInjectedScriptHost::getInternalProperties(ExecState* exec) { if (exec->argumentCount() < 1) return jsUndefined(); VM& vm = exec->vm(); JSValue value = exec->uncheckedArgument(0); if (JSPromise* promise = jsDynamicCast<JSPromise*>(value)) { unsigned index = 0; JSArray* array = constructEmptyArray(exec, nullptr); if (UNLIKELY(vm.exception())) return jsUndefined(); switch (promise->status(exec->vm())) { case JSPromise::Status::Pending: array->putDirectIndex(exec, index++, constructInternalProperty(exec, ASCIILiteral("status"), jsNontrivialString(exec, ASCIILiteral("pending")))); break; case JSPromise::Status::Fulfilled: array->putDirectIndex(exec, index++, constructInternalProperty(exec, ASCIILiteral("status"), jsNontrivialString(exec, ASCIILiteral("resolved")))); array->putDirectIndex(exec, index++, constructInternalProperty(exec, ASCIILiteral("result"), promise->result(exec->vm()))); break; case JSPromise::Status::Rejected: array->putDirectIndex(exec, index++, constructInternalProperty(exec, ASCIILiteral("status"), jsNontrivialString(exec, ASCIILiteral("rejected")))); array->putDirectIndex(exec, index++, constructInternalProperty(exec, ASCIILiteral("result"), promise->result(exec->vm()))); break; } // FIXME: <https://webkit.org/b/141664> Web Inspector: ES6: Improved Support for Promises - Promise Reactions return array; } if (JSBoundFunction* boundFunction = jsDynamicCast<JSBoundFunction*>(value)) { unsigned index = 0; JSArray* array = constructEmptyArray(exec, nullptr); if (UNLIKELY(vm.exception())) return jsUndefined(); array->putDirectIndex(exec, index++, constructInternalProperty(exec, "targetFunction", boundFunction->targetFunction())); array->putDirectIndex(exec, index++, constructInternalProperty(exec, "boundThis", boundFunction->boundThis())); if (boundFunction->boundArgs()) array->putDirectIndex(exec, index++, constructInternalProperty(exec, "boundArgs", boundFunction->boundArgs())); return array; } if (ProxyObject* proxy = jsDynamicCast<ProxyObject*>(value)) { unsigned index = 0; JSArray* array = constructEmptyArray(exec, nullptr, 2); if (UNLIKELY(vm.exception())) return jsUndefined(); array->putDirectIndex(exec, index++, constructInternalProperty(exec, ASCIILiteral("target"), proxy->target())); array->putDirectIndex(exec, index++, constructInternalProperty(exec, ASCIILiteral("handler"), proxy->handler())); return array; } if (JSObject* iteratorObject = jsDynamicCast<JSObject*>(value)) { if (iteratorObject->getDirect(exec->vm(), exec->vm().propertyNames->builtinNames().arrayIteratorNextIndexPrivateName())) { JSValue iteratedValue = iteratorObject->getDirect(exec->vm(), exec->vm().propertyNames->builtinNames().iteratedObjectPrivateName()); JSValue kind = iteratorObject->getDirect(exec->vm(), exec->vm().propertyNames->builtinNames().arrayIteratorKindPrivateName()); unsigned index = 0; JSArray* array = constructEmptyArray(exec, nullptr, 2); if (UNLIKELY(vm.exception())) return jsUndefined(); array->putDirectIndex(exec, index++, constructInternalProperty(exec, "array", iteratedValue)); array->putDirectIndex(exec, index++, constructInternalProperty(exec, "kind", kind)); return array; } } if (JSArrayIterator* arrayIterator = jsDynamicCast<JSArrayIterator*>(value)) { String kind; switch (arrayIterator->kind(exec)) { case ArrayIterateKey: kind = ASCIILiteral("key"); break; case ArrayIterateValue: kind = ASCIILiteral("value"); break; case ArrayIterateKeyValue: kind = ASCIILiteral("key+value"); break; } unsigned index = 0; JSArray* array = constructEmptyArray(exec, nullptr, 2); if (UNLIKELY(vm.exception())) return jsUndefined(); array->putDirectIndex(exec, index++, constructInternalProperty(exec, "array", arrayIterator->iteratedValue(exec))); array->putDirectIndex(exec, index++, constructInternalProperty(exec, "kind", jsNontrivialString(exec, kind))); return array; } if (JSMapIterator* mapIterator = jsDynamicCast<JSMapIterator*>(value)) { String kind; switch (mapIterator->kind()) { case MapIterateKey: kind = ASCIILiteral("key"); break; case MapIterateValue: kind = ASCIILiteral("value"); break; case MapIterateKeyValue: kind = ASCIILiteral("key+value"); break; } unsigned index = 0; JSArray* array = constructEmptyArray(exec, nullptr, 2); if (UNLIKELY(vm.exception())) return jsUndefined(); array->putDirectIndex(exec, index++, constructInternalProperty(exec, "map", mapIterator->iteratedValue())); array->putDirectIndex(exec, index++, constructInternalProperty(exec, "kind", jsNontrivialString(exec, kind))); return array; } if (JSSetIterator* setIterator = jsDynamicCast<JSSetIterator*>(value)) { String kind; switch (setIterator->kind()) { case SetIterateKey: kind = ASCIILiteral("key"); break; case SetIterateValue: kind = ASCIILiteral("value"); break; case SetIterateKeyValue: kind = ASCIILiteral("key+value"); break; } unsigned index = 0; JSArray* array = constructEmptyArray(exec, nullptr, 2); if (UNLIKELY(vm.exception())) return jsUndefined(); array->putDirectIndex(exec, index++, constructInternalProperty(exec, "set", setIterator->iteratedValue())); array->putDirectIndex(exec, index++, constructInternalProperty(exec, "kind", jsNontrivialString(exec, kind))); return array; } if (JSStringIterator* stringIterator = jsDynamicCast<JSStringIterator*>(value)) { unsigned index = 0; JSArray* array = constructEmptyArray(exec, nullptr, 1); if (UNLIKELY(vm.exception())) return jsUndefined(); array->putDirectIndex(exec, index++, constructInternalProperty(exec, "string", stringIterator->iteratedValue(exec))); return array; } if (JSPropertyNameIterator* propertyNameIterator = jsDynamicCast<JSPropertyNameIterator*>(value)) { unsigned index = 0; JSArray* array = constructEmptyArray(exec, nullptr, 1); if (UNLIKELY(vm.exception())) return jsUndefined(); array->putDirectIndex(exec, index++, constructInternalProperty(exec, "object", propertyNameIterator->iteratedValue())); return array; } return jsUndefined(); }