static JSValue getNthValueOnKeyPath(ExecState* exec, JSValue rootValue, const Vector<String>& keyPathElements, size_t index) { JSValue currentValue(rootValue); ASSERT(index <= keyPathElements.size()); for (size_t i = 0; i < index; i++) { JSValue parentValue(currentValue); if (!get(exec, parentValue, keyPathElements[i], currentValue)) return jsUndefined(); } return currentValue; }
static v8::Handle<v8::Value> getNthValueOnKeyPath(v8::Handle<v8::Value>& rootValue, const Vector<String>& keyPathElements, size_t index, v8::Isolate* isolate) { v8::Handle<v8::Value> currentValue(rootValue); ASSERT(index <= keyPathElements.size()); for (size_t i = 0; i < index; ++i) { v8::Handle<v8::Value> parentValue(currentValue); if (!get(parentValue, keyPathElements[i], currentValue, isolate)) return v8Undefined(); } return currentValue; }
static bool canInjectNthValueOnKeyPath(ExecState* exec, JSValue rootValue, const Vector<String>& keyPathElements, size_t index) { if (!rootValue.isObject()) return false; JSValue currentValue(rootValue); ASSERT(index <= keyPathElements.size()); for (size_t i = 0; i < index; ++i) { JSValue parentValue(currentValue); const String& keyPathElement = keyPathElements[i]; if (!get(exec, parentValue, keyPathElement, currentValue)) return canSet(parentValue, keyPathElement); } return true; }
static bool canInjectNthValueOnKeyPath(v8::Handle<v8::Value>& rootValue, const Vector<String>& keyPathElements, size_t index, v8::Isolate* isolate) { if (!rootValue->IsObject()) return false; v8::Handle<v8::Value> currentValue(rootValue); ASSERT(index <= keyPathElements.size()); for (size_t i = 0; i < index; ++i) { v8::Handle<v8::Value> parentValue(currentValue); const String& keyPathElement = keyPathElements[i]; if (!get(parentValue, keyPathElement, currentValue, isolate)) return canSet(parentValue, keyPathElement); } return true; }
static JSValue ensureNthValueOnKeyPath(ExecState* exec, JSValue rootValue, const Vector<String>& keyPathElements, size_t index) { JSValue currentValue(rootValue); ASSERT(index <= keyPathElements.size()); for (size_t i = 0; i < index; i++) { JSValue parentValue(currentValue); const String& keyPathElement = keyPathElements[i]; if (!get(exec, parentValue, keyPathElement, currentValue)) { JSObject* object = constructEmptyObject(exec); if (!set(exec, parentValue, keyPathElement, JSValue(object))) return jsUndefined(); currentValue = JSValue(object); } } return currentValue; }
static v8::Handle<v8::Value> ensureNthValueOnKeyPath(v8::Handle<v8::Value>& rootValue, const Vector<String>& keyPathElements, size_t index, v8::Isolate* isolate) { v8::Handle<v8::Value> currentValue(rootValue); ASSERT(index <= keyPathElements.size()); for (size_t i = 0; i < index; ++i) { v8::Handle<v8::Value> parentValue(currentValue); const String& keyPathElement = keyPathElements[i]; if (!get(parentValue, keyPathElement, currentValue, isolate)) { v8::Handle<v8::Object> object = v8::Object::New(); if (!set(parentValue, keyPathElement, object, isolate)) return v8Undefined(); currentValue = object; } } return currentValue; }