aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbors-servo <lbergstrom+bors@mozilla.com>2015-11-11 23:15:15 +0530
committerbors-servo <lbergstrom+bors@mozilla.com>2015-11-11 23:15:15 +0530
commit12f6ba29a74029fa8c83cc7274181d441e1e52dd (patch)
tree449ede9784e35351d4445e107854bf27f79afde4
parent01ff78b438fe905b02735762d696408b4d073e90 (diff)
parente33330db4eb9d9187c98139aad732ff86ab9d828 (diff)
downloadservo-12f6ba29a74029fa8c83cc7274181d441e1e52dd.tar.gz
servo-12f6ba29a74029fa8c83cc7274181d441e1e52dd.zip
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 -->
-rw-r--r--components/script/dom/bindings/codegen/CodegenRust.py7
-rw-r--r--components/script/dom/bindings/conversions.rs23
-rw-r--r--components/script/dom/webglrenderingcontext.rs5
-rw-r--r--components/script/dom/webidls/WebGLRenderingContext.webidl2
-rw-r--r--tests/wpt/mozilla/meta/MANIFEST.json12
-rw-r--r--tests/wpt/mozilla/tests/mozilla/webgl/context_creation_error.html (renamed from tests/wpt/mozilla/tests/mozilla/webgl_context_creation_error.html)0
-rw-r--r--tests/wpt/mozilla/tests/mozilla/webgl/get_supported_extensions.html20
7 files changed, 64 insertions, 5 deletions
diff --git a/components/script/dom/bindings/codegen/CodegenRust.py b/components/script/dom/bindings/codegen/CodegenRust.py
index 5ac6c455e39..260ef1e9006 100644
--- a/components/script/dom/bindings/codegen/CodegenRust.py
+++ b/components/script/dom/bindings/codegen/CodegenRust.py
@@ -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
diff --git a/components/script/dom/bindings/conversions.rs b/components/script/dom/bindings/conversions.rs
index 45279e7a966..493ed4c0c27 100644
--- a/components/script/dom/bindings/conversions.rs
+++ b/components/script/dom/bindings/conversions.rs
@@ -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) {
diff --git a/components/script/dom/webglrenderingcontext.rs b/components/script/dom/webglrenderingcontext.rs
index 875f88628f4..4855bcc36de 100644
--- a/components/script/dom/webglrenderingcontext.rs
+++ b/components/script/dom/webglrenderingcontext.rs
@@ -245,6 +245,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.
// `getSupportedExtensions` cannot be implemented as of right now (see #544)
diff --git a/components/script/dom/webidls/WebGLRenderingContext.webidl b/components/script/dom/webidls/WebGLRenderingContext.webidl
index 957220efa54..27019ed7754 100644
--- a/components/script/dom/webidls/WebGLRenderingContext.webidl
+++ b/components/script/dom/webidls/WebGLRenderingContext.webidl
@@ -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);
diff --git a/tests/wpt/mozilla/meta/MANIFEST.json b/tests/wpt/mozilla/meta/MANIFEST.json
index 117bdbf5407..30c6d7f71a4 100644
--- a/tests/wpt/mozilla/meta/MANIFEST.json
+++ b/tests/wpt/mozilla/meta/MANIFEST.json
@@ -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": [
diff --git a/tests/wpt/mozilla/tests/mozilla/webgl_context_creation_error.html b/tests/wpt/mozilla/tests/mozilla/webgl/context_creation_error.html
index 8b62ba1fd8e..8b62ba1fd8e 100644
--- a/tests/wpt/mozilla/tests/mozilla/webgl_context_creation_error.html
+++ b/tests/wpt/mozilla/tests/mozilla/webgl/context_creation_error.html
diff --git a/tests/wpt/mozilla/tests/mozilla/webgl/get_supported_extensions.html b/tests/wpt/mozilla/tests/mozilla/webgl/get_supported_extensions.html
new file mode 100644
index 00000000000..691535db476
--- /dev/null
+++ b/tests/wpt/mozilla/tests/mozilla/webgl/get_supported_extensions.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>