Last active
February 23, 2016 16:22
-
-
Save vadimtsushko/06f238dc9c364f403dfa to your computer and use it in GitHub Desktop.
How to read properties from opaque dynamic javascript map
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<!-- | |
Copyright (c) 2016, <your name>. All rights reserved. Use of this source code | |
is governed by a BSD-style license that can be found in the LICENSE file. | |
--> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<meta name="scaffolded-by" content="https://github.com/google/stagehand"> | |
<title>test_interop</title> | |
<link rel="stylesheet" href="styles.css"> | |
<script type="text/javascript"> | |
function mapFromJs() { | |
return {message: 'HELLO FROM JS', level: 'INFO'}; | |
} | |
</script> | |
<script defer src="main.dart" type="application/dart"></script> | |
<script defer src="packages/browser/dart.js"></script> | |
</head> | |
<body> | |
<div id="output"></div> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Copyright (c) 2016, <your name>. All rights reserved. Use of this source code | |
// is governed by a BSD-style license that can be found in the LICENSE file. | |
import 'dart:html'; | |
import "package:js/js.dart"; | |
void main() { | |
var v = mapFromJs(); | |
var message = getValue(v,'message'); | |
print('message $message'); | |
querySelector('#output').text = message.toString(); | |
} | |
@JS() | |
external mapFromJs(); | |
@JS() | |
@anonymous | |
class Description { | |
external get value; | |
external factory Description({bool configurable, bool enumerable, value}); | |
} | |
@JS('Object.defineProperty') | |
external void defineProperty(o, String prop, Description description); | |
setValue(o, String key, value) => | |
defineProperty(o, key, new Description(value: value)); | |
@JS('Object.getOwnPropertyDescriptor') | |
external Description getOwnPropertyDescriptor(o, String prop); | |
getValue(o, String key)=> getOwnPropertyDescriptor(o,key)?.value; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment