mirror of
https://github.com/servo/servo.git
synced 2025-07-22 23:03:42 +01:00
Auto merge of #8412 - ecoal95:webidl-sequence-return, r=jdm
Add WebIDL sequence return values And use it for `WebGLRenderingContext::getSupportedExtensions`. Part of #544 <!-- Reviewable:start --> [<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/8412) <!-- Reviewable:end -->
This commit is contained in:
commit
12f6ba29a7
7 changed files with 64 additions and 5 deletions
|
@ -1295,7 +1295,12 @@ def getRetvalDeclarationForType(returnType, descriptorProvider):
|
|||
if returnType.isObject() or returnType.isSpiderMonkeyInterface():
|
||||
return CGGeneric("*mut JSObject")
|
||||
if returnType.isSequence():
|
||||
raise TypeError("We don't support sequence return values")
|
||||
inner = returnType.unroll()
|
||||
result = getRetvalDeclarationForType(inner, descriptorProvider)
|
||||
result = CGWrapper(result, pre="Vec<", post=">")
|
||||
if returnType.nullable():
|
||||
result = CGWrapper(result, pre="Option<", post=">")
|
||||
return result
|
||||
if returnType.isDictionary():
|
||||
nullable = returnType.nullable()
|
||||
dictName = returnType.inner.name if nullable else returnType.name
|
||||
|
|
|
@ -46,6 +46,7 @@ use js::jsapi::{HandleId, HandleObject, HandleValue, JS_GetClass};
|
|||
use js::jsapi::{JSClass, JSContext, JSObject, JSString, MutableHandleValue};
|
||||
use js::jsapi::{JS_GetLatin1StringCharsAndLength, JS_GetReservedSlot};
|
||||
use js::jsapi::{JS_GetTwoByteStringCharsAndLength, JS_NewStringCopyN};
|
||||
use js::jsapi::{JS_NewArrayObject1, JS_DefineElement, RootedValue, RootedObject};
|
||||
use js::jsapi::{JS_NewUCStringCopyN, JS_StringHasLatin1Chars, JS_WrapValue};
|
||||
use js::jsval::{BooleanValue, Int32Value, NullValue, UInt32Value, UndefinedValue};
|
||||
use js::jsval::{JSVal, ObjectOrNullValue, ObjectValue, StringValue};
|
||||
|
@ -811,6 +812,28 @@ impl<T: FromJSValConvertible> FromJSValConvertible for Option<T> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<T: ToJSValConvertible> ToJSValConvertible for Vec<T> {
|
||||
fn to_jsval(&self, cx: *mut JSContext, rval: MutableHandleValue) {
|
||||
let js_array = RootedObject::new(cx,
|
||||
unsafe { JS_NewArrayObject1(cx, self.len() as libc::size_t) });
|
||||
assert!(!js_array.handle().is_null());
|
||||
|
||||
for (index, obj) in self.iter().enumerate() {
|
||||
let mut val = RootedValue::new(cx, UndefinedValue());
|
||||
obj.to_jsval(cx, val.handle_mut());
|
||||
|
||||
unsafe {
|
||||
assert!(JS_DefineElement(cx, js_array.handle(),
|
||||
index as u32, val.handle(), js::JSPROP_ENUMERATE, None, None));
|
||||
}
|
||||
}
|
||||
|
||||
unsafe {
|
||||
rval.set(ObjectValue(&*js_array.handle().get()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//http://heycam.github.io/webidl/#es-object
|
||||
impl ToJSValConvertible for *mut JSObject {
|
||||
fn to_jsval(&self, cx: *mut JSContext, rval: MutableHandleValue) {
|
||||
|
|
|
@ -244,6 +244,11 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
|
|||
})
|
||||
}
|
||||
|
||||
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.14
|
||||
fn GetSupportedExtensions(&self) -> Option<Vec<DOMString>> {
|
||||
Some(vec![])
|
||||
}
|
||||
|
||||
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.14
|
||||
fn GetExtension(&self, _cx: *mut JSContext, _name: DOMString) -> *mut JSObject {
|
||||
// TODO(ecoal95) we actually do not support extensions.
|
||||
|
|
|
@ -471,7 +471,7 @@ interface WebGLRenderingContextBase
|
|||
[WebGLHandlesContextLoss] WebGLContextAttributes? getContextAttributes();
|
||||
//[WebGLHandlesContextLoss] boolean isContextLost();
|
||||
|
||||
//sequence<DOMString>? getSupportedExtensions();
|
||||
sequence<DOMString>? getSupportedExtensions();
|
||||
object? getExtension(DOMString name);
|
||||
|
||||
void activeTexture(GLenum texture);
|
||||
|
|
|
@ -5047,10 +5047,16 @@
|
|||
"url": "/_mozilla/mozilla/variadic-interface.html"
|
||||
}
|
||||
],
|
||||
"mozilla/webgl_context_creation_error.html": [
|
||||
"mozilla/webgl/context_creation_error.html": [
|
||||
{
|
||||
"path": "mozilla/webgl_context_creation_error.html",
|
||||
"url": "/_mozilla/mozilla/webgl_context_creation_error.html"
|
||||
"path": "mozilla/webgl/context_creation_error.html",
|
||||
"url": "/_mozilla/mozilla/webgl/context_creation_error.html"
|
||||
}
|
||||
],
|
||||
"mozilla/webgl/get_supported_extensions.html": [
|
||||
{
|
||||
"path": "mozilla/webgl/get_supported_extensions.html",
|
||||
"url": "/_mozilla/mozilla/webgl/get_supported_extensions.html"
|
||||
}
|
||||
],
|
||||
"mozilla/websocket_connection_fail.html": [
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
<!doctype html>
|
||||
<meta charset="utf-8">
|
||||
<title>WebGLContextEvent getSupportedExtensions test</title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<script>
|
||||
test(function() {
|
||||
var gl = document.createElement("canvas").getContext("webgl");
|
||||
|
||||
if (!gl)
|
||||
return;
|
||||
|
||||
var extensions = gl.getSupportedExtensions();
|
||||
assert_true(Array.isArray(extensions), "getSupportedExtensions should return an array");
|
||||
|
||||
for (var i = 0; i < extensions.length; ++i)
|
||||
assert_true(typeof(extensions[i]) === "string", "Extensions should be strings, got " + typeof(extensions[i]));
|
||||
|
||||
});
|
||||
</script>
|
Loading…
Add table
Add a link
Reference in a new issue