示例#1
0
	static result_type from_v8(v8::Isolate* isolate, v8::Handle<v8::Value> value)
	{
		v8::HandleScope scope(isolate);

		result_type result;

		if (value->IsArray())
		{
			v8::Local<v8::Array> arr = value.As<v8::Array>();
			v8::Local<v8::Value> x = arr->Get(0), y = arr->Get(1);
			if (arr->Length() != 2 || !x->IsNumber() || !y->IsNumber())
			{
				throw std::invalid_argument("expected [x, y] array");
			}
			result.x = v8pp::from_v8<T>(isolate, x);
			result.y = v8pp::from_v8<T>(isolate, y);
		}
		else if (value->IsObject())
		{
			v8::Local<v8::Object> obj = value.As<v8::Object>();
			if (!get_option(isolate, obj, "x", result.x) || !get_option(isolate, obj, "y", result.y))
			{
				throw std::invalid_argument("expected {x, y} object");
			}
		}
		else
		{
			throw std::invalid_argument("expected [x, y] array or {x, y} object");
		}
		return result;
	}
示例#2
0
文件: v8base.cpp 项目: pgmsoul/GitLib
	//Twin
	void PointJsFromC(v8::Handle<Value> value,cs::Twin* r){
		HandleScope store;
		if(!value->IsObject()) return;
		Local<Object> vObj = value->ToObject();
		vObj->Set(String::New("x"),Int32::New(r->x));
		vObj->Set(String::New("y"),Int32::New(r->y));
	}
QJsonObject QV8JsonWrapper::toJsonObject(v8::Handle<v8::Value> value,
                                         V8ObjectSet &visitedObjects)
{
    QJsonObject result;
    if (!value->IsObject() || value->IsArray() || value->IsFunction())
        return result;

    v8::Handle<v8::Object> v8object(value.As<v8::Object>());
    if (visitedObjects.contains(v8object)) {
        // Avoid recursion.
        // For compatibility with QVariant{List,Map} conversion, we return an
        // empty object (and no error is thrown).
        return result;
    }

    visitedObjects.insert(v8object);

    v8::Local<v8::Array> propertyNames = m_engine->getOwnPropertyNames(v8object);
    uint32_t length = propertyNames->Length();
    for (uint32_t i = 0; i < length; ++i) {
        v8::Local<v8::Value> name = propertyNames->Get(i);
        v8::Local<v8::Value> propertyValue = v8object->Get(name);
        if (!propertyValue->IsFunction())
            result.insert(QJSConverter::toString(name->ToString()),
                          toJsonValue(propertyValue, visitedObjects));
    }

    visitedObjects.remove(v8object);

    return result;
}
示例#4
0
	static result_type from_v8(v8::Isolate* isolate, v8::Handle<v8::Value> value)
	{
		v8::HandleScope scope(isolate);

		result_type result;

		if (value->IsArray())
		{
			v8::Local<v8::Array> arr = value.As<v8::Array>();
			v8::Local<v8::Value> width = arr->Get(0), height = arr->Get(1);
			if (arr->Length() != 2 || !width->IsNumber() || !height->IsNumber())
			{
				throw std::invalid_argument("expected [width, height] array");
			}
			result.width = v8pp::from_v8<T>(isolate, width);
			result.height = v8pp::from_v8<T>(isolate, height);
		}
		else if (value->IsObject())
		{
			v8::Local<v8::Object> obj = value.As<v8::Object>();
			if (!get_option(isolate, obj, "width", result.width) || !get_option(isolate, obj, "height", result.height))
			{
				throw std::invalid_argument("expected {width, height} object");
			}
		}
		else
		{
			throw std::invalid_argument("expected [width, height] array or {width, height} object");
		}
		return result;
	}
// XPath-related utilities
RefPtr<XPathNSResolver> V8DOMWrapper::getXPathNSResolver(v8::Handle<v8::Value> value, V8Proxy* proxy)
{
    RefPtr<XPathNSResolver> resolver;
    if (V8XPathNSResolver::HasInstance(value))
        resolver = V8XPathNSResolver::toNative(v8::Handle<v8::Object>::Cast(value));
    else if (value->IsObject())
        resolver = V8CustomXPathNSResolver::create(value->ToObject());
    return resolver;
}
static bool get(v8::Handle<v8::Value>& object, const String& keyPathElement, v8::Handle<v8::Value>& result, v8::Isolate* isolate)
{
    if (object->IsString() && keyPathElement == "length") {
        int32_t length = v8::Handle<v8::String>::Cast(object)->Length();
        result = v8::Number::New(isolate, length);
        return true;
    }
    return object->IsObject() && getValueFrom(v8String(isolate, keyPathElement), result);
}
示例#7
0
文件: v8base.cpp 项目: pgmsoul/GitLib
	//*,{
	//	"type":"function",
	//	"name":"log([text],[color])",
	//	"text":"把文本输出到日志窗口。",
	//	"param":[
	//		{
	//			"type":"string",
	//			"name":"[text]",
	//			"text":"要输出的文本,如果此参数缺省,输出一个空行。"
	//		},
	//		{
	//			"type":"integer",
	//			"name":"[color]",
	//			"text":"文本的颜色,缺省是白色。"
	//		}
	//	],
	//	"return":{
	//		"type":"void",
	//		"text":"函数没有返回值。"
	//	},
	//	"remark":[
	//		"输出窗口是一个用于显示日志消息的窗口,不能响应用户的输入,但是可以控制字体大小、字体颜色、背景颜色。日志窗口有自己的消息循环,与主城市是否是窗口程序无关。"
	//	],
	//	"member":[
	//{
	//	"type":"function",
	//	"name":"show([exit])",
	//	"text":"显示日志窗口。",
	//	"param":[
	//		{
	//			"type":"boolean",
	//			"name":"exit",
	//			"text":"当用户关闭日志窗口时,是否退出程序,缺省是 true。"
	//		}
	//	],
	//	"return":{
	//		"type":"void",
	//		"text":"没有返回值。"
	//	}
	//}
	//,{
	//	"type":"function",
	//	"name":"close()",
	//	"text":"隐藏日志窗口,但是日志不会被清空。",
	//	"return":{
	//		"type":"void",
	//		"text":"这个函数没有返回值。"
	//	}
	//}
	//,{
	//	"type":"function",
	//	"name":"setMaxLine([count])",
	//	"text":"设置日志窗口最大的文本行数,如果日志达到这个行数,前面的日志会被舍弃。",
	//	"param":[
	//		{
	//			"type":"integer",
	//			"name":"[count]",
	//			"text":"可能的最大行数,缺省是 1000"
	//		}
	//	],
	//	"return":{
	//		"type":"void",
	//		"text":"这个函数没有返回值。"
	//	}
	//}
	//,{
	//	"type":"function",
	//	"name":"setFontSize(size)",
	//	"text":"设置输出文本的字体大小,这个设置是会影响所有文本。",
	//	"param":[
	//		{
	//			"type":"integer",
	//			"name":"size",
	//			"text":"字体的尺寸,缺省是 16."
	//		}
	//	],
	//	"return":{
	//		"type":"void",
	//		"text":"这个函数没有返回值。"
	//	}
	//},
	//{
	//	"type":"function",
	//	"name":"setBkColor(color)",
	//	"text":"设置输出窗口的背景色,缺省是黑色。",
	//	"param":[
	//		{
	//			"type":"integer",
	//			"name":"color",
	//			"text":"颜色值。"
	//		}
	//	],
	//	"return":{
	//		"type":"void",
	//		"text":"这个函数没有返回值。"
	//	}
	//},
	//{
	//	"type":"function",
	//	"name":"clear()",
	//	"text":"清空所有日志。",
	//	"return":{
	//		"type":"void",
	//		"text":"这个函数没有返回值。"
	//	}
	//}
	//],"source":"D:\\SoftProject\\GitLib\\jsuser\\example\\logwnd.jsuser"}//*
	void RectJsFromC(v8::Handle<Value> value,cs::Rect* r){
		HandleScope store;
		if(!value->IsObject()) return;
		Local<Object> vObj = value->ToObject();
		vObj->Set(String::New("left"),Int32::New(r->left));
		vObj->Set(String::New("top"),Int32::New(r->top));
		vObj->Set(String::New("right"),Int32::New(r->right));
		vObj->Set(String::New("bottom"),Int32::New(r->bottom));
	}
PassRefPtr<XPathNSResolver> toXPathNSResolver(v8::Handle<v8::Value> value)
{
    RefPtr<XPathNSResolver> resolver;
    if (V8XPathNSResolver::HasInstance(value))
        resolver = V8XPathNSResolver::toNative(v8::Handle<v8::Object>::Cast(value));
    else if (value->IsObject())
        resolver = V8CustomXPathNSResolver::create(value->ToObject());
    return resolver;
}
示例#9
0
v8::Handle<v8::Object> V8PerIsolateData::findInstanceInPrototypeChain(const WrapperTypeInfo* info, v8::Handle<v8::Value> value, DOMTemplateMap& domTemplateMap)
{
    if (value.IsEmpty() || !value->IsObject())
        return v8::Handle<v8::Object>();
    DOMTemplateMap::iterator result = domTemplateMap.find(info);
    if (result == domTemplateMap.end())
        return v8::Handle<v8::Object>();
    v8::Handle<v8::FunctionTemplate> templ = result->value.Get(m_isolate);
    return v8::Handle<v8::Object>::Cast(value)->FindInstanceInPrototypeChain(templ);
}
示例#10
0
v8::Handle<v8::Value> JS_GetListValue(v8::Handle<v8::Value> pList, int index)
{

	if(!pList.IsEmpty() && pList->IsObject())
	{
		v8::Local<v8::Object> obj = pList->ToObject();
		return obj->Get(index);
	}
	return v8::Handle<v8::Value>();
}
V8NodeFilterCondition::V8NodeFilterCondition(v8::Handle<v8::Value> filter, v8::Handle<v8::Object> owner, ScriptState* scriptState)
    : m_scriptState(scriptState)
{
    // ..acceptNode(..) will only dispatch m_filter if m_filter->IsObject().
    // We'll make sure m_filter is either usable by acceptNode or empty.
    // (See the fast/dom/node-filter-gc test for a case where 'empty' happens.)
    if (!filter.IsEmpty() && filter->IsObject()) {
        V8HiddenValue::setHiddenValue(scriptState->isolate(), owner, V8HiddenValue::condition(scriptState->isolate()), filter);
        m_filter.set(scriptState->isolate(), filter);
        m_filter.setWeak(this, &setWeakCallback);
    }
}
示例#12
0
文件: v8base.cpp 项目: pgmsoul/GitLib
	bool PointJsToC(v8::Handle<Value> value,cs::Twin* r){
		HandleScope store;
		if(!value->IsObject()) return false;
		Local<Object> vObj = value->ToObject();
		Local<Value> vx = vObj->Get(String::New("x"));
		if(vx->IsUndefined()) return false;
		Local<Value> vy = vObj->Get(String::New("y"));
		if(vy->IsUndefined()) return false;
		r->x = vx->Int32Value();
		r->y = vy->Int32Value();
		return true;
	}
示例#13
0
static PassRefPtr<JSONValue> v8ToJSONValue(v8::Handle<v8::Value> value, int maxDepth, v8::Isolate* isolate)
{
    if (value.IsEmpty()) {
        ASSERT_NOT_REACHED();
        return 0;
    }

    if (!maxDepth)
        return 0;
    maxDepth--;

    if (value->IsNull() || value->IsUndefined())
        return JSONValue::null();
    if (value->IsBoolean())
        return JSONBasicValue::create(value->BooleanValue());
    if (value->IsNumber())
        return JSONBasicValue::create(value->NumberValue());
    if (value->IsString())
        return JSONString::create(toCoreString(value.As<v8::String>()));
    if (value->IsArray()) {
        v8::Handle<v8::Array> array = v8::Handle<v8::Array>::Cast(value);
        RefPtr<JSONArray> inspectorArray = JSONArray::create();
        uint32_t length = array->Length();
        for (uint32_t i = 0; i < length; i++) {
            v8::Local<v8::Value> value = array->Get(v8::Int32::New(isolate, i));
            RefPtr<JSONValue> element = v8ToJSONValue(value, maxDepth, isolate);
            if (!element)
                return 0;
            inspectorArray->pushValue(element);
        }
        return inspectorArray;
    }
    if (value->IsObject()) {
        RefPtr<JSONObject> jsonObject = JSONObject::create();
        v8::Handle<v8::Object> object = v8::Handle<v8::Object>::Cast(value);
        v8::Local<v8::Array> propertyNames = object->GetPropertyNames();
        uint32_t length = propertyNames->Length();
        for (uint32_t i = 0; i < length; i++) {
            v8::Local<v8::Value> name = propertyNames->Get(v8::Int32::New(isolate, i));
            // FIXME(yurys): v8::Object should support GetOwnPropertyNames
            if (name->IsString() && !object->HasRealNamedProperty(v8::Handle<v8::String>::Cast(name)))
                continue;
            RefPtr<JSONValue> propertyValue = v8ToJSONValue(object->Get(name), maxDepth, isolate);
            if (!propertyValue)
                return 0;
            V8TRYCATCH_FOR_V8STRINGRESOURCE_RETURN(V8StringResource<WithNullCheck>, nameString, name, 0);
            jsonObject->setValue(nameString, propertyValue);
        }
        return jsonObject;
    }
    ASSERT_NOT_REACHED();
    return 0;
}
示例#14
0
v8::Handle<v8::Function> V8AdaptorFunction::wrap(v8::Handle<v8::Object> object, const AtomicString& name, v8::Isolate* isolate)
{
    if (object.IsEmpty() || !object->IsObject())
        return v8::Handle<v8::Function>();
    v8::Handle<v8::Function> adaptor = v8::Handle<v8::Function>::Cast(getTemplate(isolate)->GetFunction());
    if (adaptor.IsEmpty())
        return v8::Handle<v8::Function>();
    adaptor->SetName(v8String(name.string(), isolate));
    adaptor->SetHiddenValue(V8HiddenPropertyName::adaptorFunctionPeer(), object);
    object->SetHiddenValue(V8HiddenPropertyName::adaptorFunctionPeer(), adaptor);
    return adaptor;
}
示例#15
0
文件: shell.cpp 项目: chiehwen/djondb
// The callback that is invoked by v8 whenever the JavaScript 'print'
// function is called.  Prints its arguments on stdout separated by
// spaces and ending with a newline.
void internalPrint(const v8::Handle<v8::Value> arg) {
	v8::HandleScope handle_scope;
	std::string cstr;
	if (arg->IsObject()) {
		v8::String::Utf8Value str(toJson(arg->ToObject(), true));
		cstr = ToCString(str);
	} else {
		v8::String::Utf8Value str(arg);
		cstr = ToCString(str);
	}
	printf("%s", cstr.c_str());
}
示例#16
0
static PassRefPtr<InspectorValue> v8ToInspectorValue(v8::Handle<v8::Value> value, int maxDepth)
{
    if (value.IsEmpty()) {
        ASSERT_NOT_REACHED();
        return 0;
    }

    if (!maxDepth)
        return 0;
    maxDepth--;

    if (value->IsNull() || value->IsUndefined())
        return InspectorValue::null();
    if (value->IsBoolean())
        return InspectorBasicValue::create(value->BooleanValue());
    if (value->IsNumber())
        return InspectorBasicValue::create(value->NumberValue());
    if (value->IsString())
        return InspectorString::create(toWebCoreString(value));
    if (value->IsArray()) {
        v8::Handle<v8::Array> array = v8::Handle<v8::Array>::Cast(value);
        RefPtr<InspectorArray> inspectorArray = InspectorArray::create();
        uint32_t length = array->Length();
        for (uint32_t i = 0; i < length; i++) {
            v8::Local<v8::Value> value = array->Get(v8::Int32::New(i));
            RefPtr<InspectorValue> element = v8ToInspectorValue(value, maxDepth);
            if (!element)
                return 0;
            inspectorArray->pushValue(element);
        }
        return inspectorArray;
    }
    if (value->IsObject()) {
        RefPtr<InspectorObject> inspectorObject = InspectorObject::create();
        v8::Handle<v8::Object> object = v8::Handle<v8::Object>::Cast(value);
        v8::Local<v8::Array> propertyNames = object->GetPropertyNames();
        uint32_t length = propertyNames->Length();
        for (uint32_t i = 0; i < length; i++) {
            v8::Local<v8::Value> name = propertyNames->Get(v8::Int32::New(i));
            // FIXME(yurys): v8::Object should support GetOwnPropertyNames
            if (name->IsString() && !object->HasRealNamedProperty(v8::Handle<v8::String>::Cast(name)))
                continue;
            RefPtr<InspectorValue> propertyValue = v8ToInspectorValue(object->Get(name), maxDepth);
            if (!propertyValue)
                return 0;
            inspectorObject->setValue(toWebCoreStringWithNullCheck(name), propertyValue);
        }
        return inspectorObject;
    }
    ASSERT_NOT_REACHED();
    return 0;
}
示例#17
0
bool V8DOMWrapper::isDOMWrapper(v8::Handle<v8::Value> value)
{
    if (value.IsEmpty() || !value->IsObject())
        return false;

    v8::Handle<v8::Object> wrapper = v8::Handle<v8::Object>::Cast(value);
    if (wrapper->InternalFieldCount() < v8DefaultWrapperInternalFieldCount)
        return false;
    ASSERT(wrapper->GetAlignedPointerFromInternalField(v8DOMWrapperObjectIndex));
    ASSERT(wrapper->GetAlignedPointerFromInternalField(v8DOMWrapperTypeIndex));

    // FIXME: Add class id checks.
    return true;
}
示例#18
0
文件: v8_mouse.cpp 项目: icedman/lov8
/**
 * Unwrap
 * Unwrap a JS object int a cpp class
 */
Mouse JSMouseUnwrap(v8::Handle<v8::Value> value) {
	if (value->ToObject()->InternalFieldCount())
		value = value->ToObject()->GetInternalField(0);
	Mouse cobj;
		if (value->IsObject()) {
	v8::Handle<v8::Object> obj = value->ToObject();
		
		cobj.x = obj->Get(v8::String::New("x"))->NumberValue();
		
		cobj.y = obj->Get(v8::String::New("y"))->NumberValue();
		
	}
	return cobj;
	}
示例#19
0
static void
makews(struct winsize *w, v8::Handle<v8::Value> size) {
	v8::Handle<v8::String> columns = NanNew<v8::String>("columns"),
		rows = NanNew<v8::String>("rows");
	w->ws_row = 24;
	w->ws_col = 80;
	w->ws_xpixel = w->ws_ypixel = 0;
	if(size->IsObject()) {
		v8::Handle<v8::Object> obj = size->ToObject();
		if(obj->Has(columns))
			w->ws_col = obj->Get(columns)->Uint32Value();
		if(obj->Has(rows))
			w->ws_row = obj->Get(rows)->Uint32Value();
	}
}
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;
}
bool V8DOMWrapper::maybeDOMWrapper(v8::Handle<v8::Value> value)
{
    if (value.IsEmpty() || !value->IsObject())
        return false;

    v8::Handle<v8::Object> object = v8::Handle<v8::Object>::Cast(value);
    if (!object->InternalFieldCount())
        return false;

    ASSERT(object->InternalFieldCount() >= v8DefaultWrapperInternalFieldCount);

    v8::Handle<v8::Value> wrapper = object->GetInternalField(v8DOMWrapperObjectIndex);
    ASSERT(wrapper->IsNumber() || wrapper->IsExternal());

    return true;
}
示例#22
0
static v8::Handle<v8::Function> eventListenerEffectiveFunction(v8::Isolate* isolate, v8::Handle<v8::Object> listenerObject)
{
    v8::Handle<v8::Function> function;
    if (listenerObject->IsFunction()) {
        function = v8::Handle<v8::Function>::Cast(listenerObject);
    } else if (listenerObject->IsObject()) {
        // Try the "handleEvent" method (EventListener interface).
        v8::Handle<v8::Value> property = listenerObject->Get(v8AtomicString(isolate, "handleEvent"));
        if (property.IsEmpty() || !property->IsFunction()) {
            // Fall back to the "constructor" property.
            property = listenerObject->Get(v8AtomicString(isolate, "constructor"));
        }
        if (!property.IsEmpty() && property->IsFunction())
            function = v8::Handle<v8::Function>::Cast(property);
    }
    return function;
}
示例#23
0
void key::Window::setDisplayMode(v8::Handle<v8::Value> newMode) {
	HandleScope scope;

	if (newMode->IsObject()) {
		this->displayMode.clear();
		auto modeObj = newMode->ToObject();
		auto propertyNames = modeObj->GetPropertyNames();
		for (uint32_t i = 0; i < propertyNames->Length(); i++) {
			auto name = propertyNames->Get(i);
			auto value = modeObj->Get(name);
			this->displayMode[cvv8::CastFromJS<std::string>(name)] = cvv8::CastFromJS<int32_t>(value);
		}

		/*if (this->device.use_count() > 0)
			this->device->notifyWindowChange(NOTIFY_CHANGE_DISPLAY_MODE);*/
	}
}
示例#24
0
    Object^ V8Interop::FromV8(v8::Handle<v8::Value> value) 
    {
        if (value->IsString()) 
        {
            return FromV8String(value);
        } 
        else if (value->IsBoolean()) 
        {
            return FromV8Boolean(value);
        } 
        else if (value->IsInt32()) 
        {
            return FromV8Int32(value);
        } 
        else if (value->IsArray()) 
        {
            return FromV8Array(value);
        } 
        else if (value->IsDate()) 
        {
            return FromV8Date(value);
        } 
        else if (value->IsNumber()) 
        {
            return FromV8Double(value);
        } 
        else if (value->IsFunction()) 
        {
            return FromV8Function(value);
        } 
        else if (value->IsExternal()) 
        {
            return FromV8External(value);
        } 
        else if (value->IsObject()) 
        {
            return FromV8Object(value);
        } 
        else if (value->IsUndefined() || value->IsNull()) 
        {
            return nullptr;
        }

        return nullptr;
    }
示例#25
0
bool decodeJSInvokableObject(v8::Handle<v8::Value> senderVal, EmersonScript*& emerScript, JSInvokableObjectInt*& simObj)
{

   if ((!senderVal->IsObject()) || (senderVal->IsUndefined()))
    {
        emerScript = NULL;
        simObj = NULL;
        return false;
    }



    v8::Handle<v8::Object>sender = v8::Handle<v8::Object>::Cast(senderVal);

    if (sender->InternalFieldCount() != JSINVOKABLE_OBJECT_TEMPLATE_FIELD_COUNT)
    {
      return false;
    }

    v8::Local<v8::External> wrapJSObj;
    wrapJSObj = v8::Local<v8::External>::Cast(sender->GetInternalField(JSINVOKABLE_OBJECT_JSOBJSCRIPT_FIELD));

    void* ptr = wrapJSObj->Value();
    emerScript = static_cast<EmersonScript*>(ptr);

    if (emerScript == NULL)
    {
        simObj = NULL;
        return false;
    }

    v8::Local<v8::External> wrapSimObjRef;
    wrapSimObjRef = v8::Local<v8::External>::Cast(sender->GetInternalField(JSINVOKABLE_OBJECT_SIMULATION_FIELD));
    void* ptr2 = wrapSimObjRef->Value();
    simObj = static_cast<JSInvokableObject::JSInvokableObjectInt*>(ptr2);

    if(!simObj)
    {
      emerScript = NULL;
      return false;
    }

    return true;

}
QJsonValue QV8JsonWrapper::toJsonValue(v8::Handle<v8::Value> value,
                                       V8ObjectSet &visitedObjects)
{
    if (value->IsString())
        return QJsonValue(QJSConverter::toString(value.As<v8::String>()));
    else if (value->IsNumber())
        return QJsonValue(value->NumberValue());
    else if (value->IsBoolean())
        return QJsonValue(value->BooleanValue());
    else if (value->IsArray())
        return toJsonArray(value.As<v8::Array>(), visitedObjects);
    else if (value->IsObject())
        return toJsonObject(value.As<v8::Object>(), visitedObjects);
    else if (value->IsNull())
        return QJsonValue(QJsonValue::Null);
    else
        return QJsonValue(QJsonValue::Undefined);
}
示例#27
0
文件: v8base.cpp 项目: pgmsoul/GitLib
	//*,{
	//	"type":"class",
	//	"name":"Point",
	//	"text":"Point 对象是一个纯 Javascript 对象,包含两个数字属性。Size 和 Point 是同一个对象的两个名称。",
	//	"member":[
	//	{
	//		"type":"property",
	//		"name":"x",
	//		"objtype":"integer",
	//		"text":"x 属性,一般表示横坐标位置或宽度。"
	//	},
	//	{
	//		"type":"property",
	//		"name":"y",
	//		"objtype":"integer",
	//		"text":"y 属性,一般表示纵坐标位置或高度。"
	//	},
	//	{
	//		"type":"function",
	//		"name":"move(dx,dy)",
	//		"text":"调整 x 和 y 属性的值。",
	//		"param":[
	//			{
	//				"type":"integer",
	//				"name":"dx",
	//				"text":"x 将会加上这个值。"
	//			},
	//			{
	//				"type":"integer",
	//				"name":"dy",
	//				"text":"y 将会加上这个值。"
	//			}
	//		],
	//		"return":{
	//			"type":"void",
	//			"text":"函数没有返回值。"
	//		}
	//	}
	//	]
	//}
	//,{
	//	"type":"class",
	//	"name":"Rect",
	//	"text":"Rect 对象是一个纯 Javascript 对象,包含四个数字属性。",
	//	"member":[
	//	{
	//		"type":"property",
	//		"name":"left",
	//		"objtype":"integer",
	//		"text":"左边界。"
	//	},
	//	{
	//		"type":"property",
	//		"name":"top",
	//		"objtype":"integer",
	//		"text":"上边界。"
	//	},
	//	{
	//		"type":"property",
	//		"name":"right",
	//		"objtype":"integer",
	//		"text":"右边界。"
	//	},
	//	{
	//		"type":"property",
	//		"name":"bottom",
	//		"objtype":"integer",
	//		"text":"下边界。"
	//	},
	//	{
	//		"type":"function",
	//		"name":"ptInRect(x,[y])",
	//		"text":"(x,y)所代表的点是否在这个矩形内,如果不传 y 参数,表示不考虑 y,只考虑 x。",
	//		"param":[
	//			{
	//				"type":"integer",
	//				"name":"x",
	//				"text":"点的 x 坐标。"
	//			},
	//			{
	//				"type":"integer",
	//				"name":"[y]",
	//				"text":"点的 y 坐标。"
	//			}
	//		],
	//		"return":{
	//			"type":"boolean",
	//			"text":"如果点在矩形内返回 true,否则返回 false。"
	//		},
	//		"remark":[
	//			"矩形的左边界和上边界上的点算矩形内部,但是右边界和下边界不算矩形内部。"
	//		]
	//	},
	//	{
	//		"type":"function",
	//		"name":"getLocation()",
	//		"text":"获取矩形的位置,也就是左上角的坐标。",
	//		"param":[
	//		],
	//		"return":{
	//			"type":"Point",
	//			"text":"返回一个 Point 对象。"
	//		}
	//	},
	//	{
	//		"type":"function",
	//		"name":"setLocation([x],[y])",
	//		"text":"设置矩形的位置,这个函数会改变矩形 4 个属性的值,但是保持大小不变。",
	//		"param":[
	//			{
	//				"type":"integer",
	//				"name":"[x]",
	//				"text":"新位置的 x 坐标,如果此值为 undefined,矩形的 left 和 right 不变。"
	//			},
	//			{
	//				"type":"integer",
	//				"name":"[y]",
	//				"text":"新位置的 y 坐标,如果此值为 undefined,矩形的 top 和 bottom 不变。"
	//			}
	//		],
	//		"return":{
	//			"type":"void",
	//			"text":"函数没有返回值。"
	//		}
	//	},
	//	{
	//		"type":"function",
	//		"name":"setSize",
	//		"text":"设置矩形的大小,这个函数通过调整 right 和 bottom 来调整矩形的大小。",
	//		"param":[
	//			{
	//				"type":"integer",
	//				"name":"[width]",
	//				"text":"矩形新的宽度,如果此值为 undefined,矩形的宽度不变。"
	//			},
	//			{
	//				"type":"integer",
	//				"name":"[height]",
	//				"text":"矩形新的高度,如果此值为 undefined,矩形的高度不变。"
	//			}
	//		],
	//		"return":{
	//			"type":"void",
	//			"text":"这个函数没有返回值。"
	//		}
	//	},
	//	{
	//		"type":"function",
	//		"name":"getSize",
	//		"text":"获取矩形的大小。",
	//		"param":[
	//		],
	//		"return":{
	//			"type":"Size",
	//			"text":"返回一个 Size 对象。"
	//		}
	//	},
	//	{
	//		"type":"function",
	//		"name":"positive",
	//		"text":"通过交换 left 和 right 或者 top 和 bottom 的值来保证,left 总是小于等于 right,top 总是小于等于 bottom。",
	//		"param":[
	//		],
	//		"return":{
	//			"type":"void",
	//			"text":"这个函数没有返回值。"
	//		}
	//	},
	//	{
	//		"type":"function",
	//		"name":"setValue(left,top,right,bottom)",
	//		"text":"设置矩形的 4 个属性,这个函数直接设置,不做任何检测。",
	//		"param":[
	//			{
	//				"type":"integer",
	//				"name":"left",
	//				"text":"要设置的 left 属性值。"
	//			},
	//			{
	//				"type":"integer",
	//				"name":"top",
	//				"text":"要设置的 top 属性值。"
	//			},
	//			{
	//				"type":"integer",
	//				"name":"right",
	//				"text":"要设置的 right 属性值。"
	//			},
	//			{
	//				"type":"integer",
	//				"name":"bottom",
	//				"text":"要设置的 bottom 属性值。"
	//			}
	//		],
	//		"return":{
	//			"type":"void",
	//			"text":"这个函数没有返回值。"
	//		}
	//	}
	//	]
	//}//*
	bool RectJsToC(v8::Handle<Value> value,cs::Rect* r){
		HandleScope store;
		if(!value->IsObject()) return false;
		Local<Object> vObj = value->ToObject();
		Local<Value> vl = vObj->Get(String::New("left"));
		if(vl->IsUndefined()) return false;
		Local<Value> vt = vObj->Get(String::New("top"));
		if(vt->IsUndefined()) return false;
		Local<Value> vr = vObj->Get(String::New("right"));
		if(vr->IsUndefined()) return false;
		Local<Value> vb = vObj->Get(String::New("bottom"));
		if(vb->IsUndefined()) return false;
		r->left = vl->Int32Value();
		r->top = vt->Int32Value();
		r->right = vr->Int32Value();
		r->bottom = vb->Int32Value();
		return true;
	}
示例#28
0
static void ReportException(Environment* env, v8::Handle<v8::Value> er, v8::Handle<v8::Message> message)
{
    v8::HandleScope scope(env->isolate());

    AppendExceptionLine(env, er, message);

    v8::Local<v8::Value> trace_value;

    if (er->IsUndefined() || er->IsNull())
        trace_value = Undefined(env->isolate());
    else
        trace_value = er->ToObject()->Get(env->stack_string());

    v8::String::Utf8Value trace(trace_value);

    // range errors have a trace member set to undefined
    if (trace.length() > 0 && !trace_value->IsUndefined()) {
        fprintf(stderr, "%s\n", *trace);
    } else {
        // this really only happens for RangeErrors, since they're the only
        // kind that won't have all this info in the trace, or when non-Error
        // objects are thrown manually.
        v8::Local<v8::Value> message;
        v8::Local<v8::Value> name;

        if (er->IsObject()) {
            v8::Local<v8::Object> err_obj = er.As<v8::Object>();
            message = err_obj->Get(env->message_string());
            name = err_obj->Get(FIXED_UTF8_STRING(env->isolate(), "name"));
        }

        if (message.IsEmpty() || message->IsUndefined() || name.IsEmpty() || name->IsUndefined()) {
            // Not an error object. Just print as-is.
            v8::String::Utf8Value message(er);
            fprintf(stderr, "%s\n", *message);
        } else {
            v8::String::Utf8Value name_string(name);
            v8::String::Utf8Value message_string(message);
            fprintf(stderr, "%s: %s\n", *name_string, *message_string);
        }
    }

    fflush(stderr);
}
示例#29
0
bool V8DOMWrapper::maybeDOMWrapper(v8::Handle<v8::Value> value)
{
    if (value.IsEmpty() || !value->IsObject())
        return false;

    v8::Handle<v8::Object> object = v8::Handle<v8::Object>::Cast(value);
    if (!object->InternalFieldCount())
        return false;

    ASSERT(object->InternalFieldCount() >= v8DefaultWrapperInternalFieldCount);

    v8::Handle<v8::Value> type = object->GetInternalField(v8DOMWrapperTypeIndex);
    ASSERT(type->IsInt32());
    ASSERT(V8ClassIndex::INVALID_CLASS_INDEX < type->Int32Value() && type->Int32Value() < V8ClassIndex::CLASSINDEX_END);

    v8::Handle<v8::Value> wrapper = object->GetInternalField(v8DOMWrapperObjectIndex);
    ASSERT(wrapper->IsNumber() || wrapper->IsExternal());

    return true;
}
示例#30
0
static Value v8ValueToValue(v8::Handle<v8::Value> v8Value)
{
    v8::HandleScope scope;
    if (v8Value->IsArray()) {
        List<Value> value;
        const v8::Handle<v8::Array> v8Array = v8::Handle<v8::Array>::Cast(v8Value);
        const uint32_t size = v8Array->Length();
        for (uint32_t i = 0; i < size; ++i) {
            if (v8Array->Has(i))
                value.append(v8ValueToValue(v8Array->Get(i)));
            else
                value.append(Value());
        }
        return Value(value);
    } else if (v8Value->IsObject()) {
        Map<String, Value> value;
        const v8::Handle<v8::Object> v8Object = v8Value->ToObject();
        const v8::Handle<v8::Array> props = v8Object->GetPropertyNames();
        const uint32_t size = props->Length();
        for (uint32_t i = 0; i < size; ++i) {
            assert(props->Has(i));
            const v8::Handle<v8::Value> name = props->Get(i);
            value[String(*v8::String::Utf8Value(name))] = v8ValueToValue(v8Object->Get(name));
        }
        return Value(value);
    } else if (v8Value->IsBoolean()) {
        return Value(v8Value->BooleanValue());
    } else if (v8Value->IsInt32() || v8Value->IsUint32()) {
        return Value(v8Value->Int32Value());
    } else if (v8Value->IsNumber()) {
        return Value(v8Value->NumberValue());
    } else if (v8Value->IsString()) {
        return Value(String(*v8::String::Utf8Value(v8Value)));
    } else {
        error() << "Unexpected v8 value type in JSONParser";
    }
    // undefined or null?
    return Value();
}