Why js code "video.src" throw an "src undefined" error in my building Chromium project?

783 views
Skip to first unread message

imdev...@gmail.com

unread,
Nov 11, 2013, 6:40:46 AM11/11/13
to chromium...@chromium.org
I build chromium.25.0.1364.172 in linux.
When I use the chrome to visit a page blow, it (v8) throw an "src undefined" error from  document.getElementById("v1").src="video.ogg".
And it works when I use setAttribute.

Could anyone tell me What cause this Problem? Any chromium building MACRO or something else?

<html>
<body>

<video id='v1' src="movie.ogg" controls="controls">
</video>

<video id='v2' src="movie.ogg" controls="controls">
</video>

<script  type="text/javascript">

  document.getElementById("v1").src="video.ogg";                        // error, throw src undefined

  document.getElementById("v2").setAttribute("src","video.ogg");  // it's ok
</script>

</body>
</html>

PhistucK

unread,
Nov 11, 2013, 3:49:54 PM11/11/13
to imdev...@gmail.com, Chromium-discuss
This error (or at least, your interpretation of the error) does not make sense. Something else is undefined.
It does not make sense, because in JavaScript, unless the object is sealed or extensions are disallowed (Object.seal and friends), setting a value to a previously undefined property simply creates that property and sets its value to the value you specify.

Like -
var blankObject = {};
blankObject.newProperty = "bla"; // This does not throw, it sets a new property.

What is the exact error you get?

By the way, when I run this code, I get no error and see two players.


PhistucK


--
--
Chromium Discussion mailing list: chromium...@chromium.org
View archives, change email options, or unsubscribe:
http://groups.google.com/a/chromium.org/group/chromium-discuss
 

To unsubscribe from this group and stop receiving emails from it, send an email to chromium-discu...@chromium.org.

imdev...@gmail.com

unread,
Nov 12, 2013, 3:53:45 AM11/12/13
to chromium...@chromium.org, imdev...@gmail.com
Thanks for your reply!
Just like what you said,the error is not thrown from the setting value,but from the getting value.
"videoObj.src" method cann't get the src attribute value in the VIDEO tag.
It seems that the webkit element attribute not reflect to the v8 object.
Could you kindly tell me more about this?Or how to solve this problem?

<html>
<body>

<video id='v1' src="movie.ogg" controls="controls">
</video>

<script  type="text/javascript">
    alert("video src:" + document.getElementById("v").src);              //  "video src:movie.ogg" is expected, but it printed: "video src:undefined".
</script>

</body>
</html>




在 2013年11月12日星期二UTC+8上午4时49分54秒,PhistucK写道:

PhistucK

unread,
Nov 12, 2013, 3:19:21 PM11/12/13
to imdev...@gmail.com, Chromium-discuss
Looks like you forgot "1". You wrote getElementById("v"), not getElementById("v1").
Look at the error - "Uncaught TypeError: Cannot read property 'src' of null". It clearly says that the problem lies with (the lack of) the object, and not with the lack of the property property.


PhistucK

imdev...@gmail.com

unread,
Nov 12, 2013, 8:38:02 PM11/12/13
to chromium...@chromium.org, imdev...@gmail.com
Sorry,I have copyed a wrong line.
Actually the page's tag id is "v".
Still the "undefined" problem
I have tried in the download pc chrome version, it works.
But in my building chrome, it is "undefined" error.

<html>
<body>

<video id='v' src="movie.ogg" controls="controls">
</video>

<script  type="text/javascript">
    alert("video src:" + document.getElementById("v").src);              //  "video src:movie.ogg" is expected, but it printed: "video src:undefined".
</script>

</body>
</html>


在 2013年11月13日星期三UTC+8上午4时19分21秒,PhistucK写道:

PhistucK

unread,
Nov 13, 2013, 1:19:02 PM11/13/13
to imdev...@gmail.com, Chromium-discuss
"in my building chrome" - are you compiling your own Chromium?
If so, I guess you messed things up there.

For me, your code alerts "video src:". No "undefined".


PhistucK
Reply all
Reply to author
Forward
0 new messages