Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle u32 property indices #24858

Merged
merged 1 commit into from Nov 27, 2019
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

@@ -16,11 +16,13 @@ use crate::dom::bindings::trace::trace_object;
use crate::dom::messageport::MessagePort;
use crate::dom::windowproxy;
use crate::script_runtime::JSContext as SafeJSContext;
use js::conversions::ToJSValConvertible;
use js::conversions::{jsstr_to_string, ToJSValConvertible};
use js::glue::{CallJitGetterOp, CallJitMethodOp, CallJitSetterOp, IsWrapper};
use js::glue::{GetCrossCompartmentWrapper, JS_GetReservedSlot, WrapperNew};
use js::glue::{UnwrapObjectDynamic, RUST_JSID_TO_INT, RUST_JSID_TO_STRING};
use js::glue::{RUST_FUNCTION_VALUE_TO_JITINFO, RUST_JSID_IS_INT, RUST_JSID_IS_STRING};
use js::glue::{
RUST_FUNCTION_VALUE_TO_JITINFO, RUST_JSID_IS_INT, RUST_JSID_IS_STRING, RUST_JSID_IS_VOID,
};
use js::jsapi::HandleId as RawHandleId;
use js::jsapi::HandleObject as RawHandleObject;
use js::jsapi::MutableHandleObject as RawMutableHandleObject;
@@ -29,7 +31,10 @@ use js::jsapi::{Heap, JSAutoRealm, JSContext, JS_FreezeObject};
use js::jsapi::{JSJitInfo, JSObject, JSTracer, JSWrapObjectCallbacks};
use js::jsapi::{JS_EnumerateStandardClasses, JS_GetLatin1StringCharsAndLength};
use js::jsapi::{JS_IsExceptionPending, JS_IsGlobalObject};
use js::jsapi::{JS_ResolveStandardClass, JS_StringHasLatin1Chars, ObjectOpResult};
use js::jsapi::{
JS_ResolveStandardClass, JS_StringHasLatin1Chars, ObjectOpResult, StringIsArrayIndex1,
StringIsArrayIndex2,
};
use js::jsval::{JSVal, UndefinedValue};
use js::rust::wrappers::JS_DeletePropertyById;
use js::rust::wrappers::JS_ForwardGetPropertyTo;
@@ -178,28 +183,41 @@ pub unsafe fn get_property_on_prototype(

/// Get an array index from the given `jsid`. Returns `None` if the given
/// `jsid` is not an integer.
pub fn get_array_index_from_id(_cx: *mut JSContext, id: HandleId) -> Option<u32> {
pub unsafe fn get_array_index_from_id(cx: *mut JSContext, id: HandleId) -> Option<u32> {
let raw_id = id.into();
unsafe {
if RUST_JSID_IS_INT(raw_id) {
return Some(RUST_JSID_TO_INT(raw_id) as u32);
}
if RUST_JSID_IS_INT(raw_id) {
return Some(RUST_JSID_TO_INT(raw_id) as u32);
}

if RUST_JSID_IS_VOID(raw_id) || !RUST_JSID_IS_STRING(raw_id) {
return None;
}

let s = jsstr_to_string(cx, RUST_JSID_TO_STRING(raw_id));
if s.len() == 0 {
return None;
}

let first = s.chars().next().unwrap();
if first.is_ascii_lowercase() {
return None;
}

let mut i: u32 = 0;
let is_array = if s.is_ascii() {
let chars = s.as_bytes();
StringIsArrayIndex1(chars.as_ptr() as *const _, chars.len() as u32, &mut i)
} else {
let chars = s.encode_utf16().collect::<Vec<u16>>();
let slice = chars.as_slice();
StringIsArrayIndex2(slice.as_ptr(), chars.len() as u32, &mut i)
};

if is_array {
Some(i)
} else {
None
}
// if id is length atom, -1, otherwise
// return if JSID_IS_ATOM(id) {
// let atom = JSID_TO_ATOM(id);
// //let s = *GetAtomChars(id);
// if s > 'a' && s < 'z' {
// return -1;
// }
//
// let i = 0;
// let str = AtomToLinearString(JSID_TO_ATOM(id));
// return if StringIsArray(str, &mut i) != 0 { i } else { -1 }
// } else {
// IdToInt32(cx, id);
// }
}

/// Find the enum equivelent of a string given by `v` in `pairs`.
@@ -1,11 +1,5 @@
[HTMLCollection-supported-property-indices.html]
type: testharness
[Handling of property names that look like integers around 2^31]
expected: FAIL

[Handling of property names that look like integers around 2^32]
expected: FAIL

[Trying to set an expando that would shadow an already-existing indexed property]
expected: FAIL

ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.