Commit 9f681fa9 authored by vitalyr@chromium.org's avatar vitalyr@chromium.org

Small API improvements:

 * Added Get and Set taking uint32_t for faster and more convenient
   access to elements.

 * Added less verbose casting for handles. Now instead of
       v8::Local<v8::String>::Cast(args[0])
   one can write
       args[0].As<v8::String>().

Review URL: http://codereview.chromium.org/660243

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@4002 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 99e67e0e
......@@ -261,6 +261,10 @@ template <class T> class V8EXPORT_INLINE Handle {
return Handle<T>(T::Cast(*that));
}
template <class S> inline Handle<S> As() {
return Handle<S>::Cast(*this);
}
private:
T* val_;
};
......@@ -295,6 +299,10 @@ template <class T> class V8EXPORT_INLINE Local : public Handle<T> {
return Local<T>(T::Cast(*that));
}
template <class S> inline Local<S> As() {
return Local<S>::Cast(*this);
}
/** Create a local handle for the content of another handle.
* The referee is kept alive by the local handle even when
* the original handle is destroyed/disposed.
......@@ -368,6 +376,10 @@ template <class T> class V8EXPORT_INLINE Persistent : public Handle<T> {
return Persistent<T>(T::Cast(*that));
}
template <class S> inline Persistent<S> As() {
return Persistent<S>::Cast(*this);
}
/**
* Creates a new persistent handle for an existing local or
* persistent handle.
......@@ -1178,6 +1190,9 @@ class V8EXPORT Object : public Value {
Handle<Value> value,
PropertyAttribute attribs = None);
bool Set(uint32_t index,
Handle<Value> value);
// Sets a local property on this object bypassing interceptors and
// overriding accessors or read-only properties.
//
......@@ -1192,6 +1207,8 @@ class V8EXPORT Object : public Value {
Local<Value> Get(Handle<Value> key);
Local<Value> Get(uint32_t index);
// TODO(1245389): Replace the type-specific versions of these
// functions with generic ones that accept a Handle<Value> key.
bool Has(Handle<String> key);
......
......@@ -1975,6 +1975,23 @@ bool v8::Object::Set(v8::Handle<Value> key, v8::Handle<Value> value,
}
bool v8::Object::Set(uint32_t index, v8::Handle<Value> value) {
ON_BAILOUT("v8::Object::Set()", return false);
ENTER_V8;
HandleScope scope;
i::Handle<i::JSObject> self = Utils::OpenHandle(this);
i::Handle<i::Object> value_obj = Utils::OpenHandle(*value);
EXCEPTION_PREAMBLE();
i::Handle<i::Object> obj = i::SetElement(
self,
index,
value_obj);
has_pending_exception = obj.is_null();
EXCEPTION_BAILOUT_CHECK(false);
return true;
}
bool v8::Object::ForceSet(v8::Handle<Value> key,
v8::Handle<Value> value,
v8::PropertyAttribute attribs) {
......@@ -2023,6 +2040,18 @@ Local<Value> v8::Object::Get(v8::Handle<Value> key) {
}
Local<Value> v8::Object::Get(uint32_t index) {
ON_BAILOUT("v8::Object::Get()", return Local<v8::Value>());
ENTER_V8;
i::Handle<i::JSObject> self = Utils::OpenHandle(this);
EXCEPTION_PREAMBLE();
i::Handle<i::Object> result = i::GetElement(self, index);
has_pending_exception = result.is_null();
EXCEPTION_BAILOUT_CHECK(Local<Value>());
return Utils::ToLocal(result);
}
Local<Value> v8::Object::GetPrototype() {
ON_BAILOUT("v8::Object::GetPrototype()", return Local<v8::Value>());
ENTER_V8;
......
......@@ -283,6 +283,12 @@ Handle<Object> GetProperty(Handle<Object> obj,
}
Handle<Object> GetElement(Handle<Object> obj,
uint32_t index) {
CALL_HEAP_FUNCTION(Runtime::GetElement(obj, index), Object);
}
Handle<Object> GetPropertyWithInterceptor(Handle<JSObject> receiver,
Handle<JSObject> holder,
Handle<String> name,
......
......@@ -233,6 +233,9 @@ Handle<Object> GetProperty(Handle<JSObject> obj,
Handle<Object> GetProperty(Handle<Object> obj,
Handle<Object> key);
Handle<Object> GetElement(Handle<Object> obj,
uint32_t index);
Handle<Object> GetPropertyWithInterceptor(Handle<JSObject> receiver,
Handle<JSObject> holder,
Handle<String> name,
......
......@@ -2857,6 +2857,11 @@ Object* Runtime::GetElementOrCharAt(Handle<Object> object, uint32_t index) {
return prototype->GetElement(index);
}
return GetElement(object, index);
}
Object* Runtime::GetElement(Handle<Object> object, uint32_t index) {
return object->GetElement(index);
}
......
......@@ -403,6 +403,7 @@ class Runtime : public AllStatic {
// Support getting the characters in a string using [] notation as
// in Firefox/SpiderMonkey, Safari and Opera.
static Object* GetElementOrCharAt(Handle<Object> object, uint32_t index);
static Object* GetElement(Handle<Object> object, uint32_t index);
static Object* SetObjectProperty(Handle<Object> object,
Handle<Object> key,
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment